创建UInt8在应用程序中失败但在Playground中进行

时间:2016-01-31 01:27:21

标签: swift uint

我已将Objective-C脚本转换为Swift以形成AAC帧的标头。但是,代码无法在应用程序中运行,并且与EXC_BAD_ACCESS崩溃。将代码复制到playground中输出我期望的没有错误。不知道该去哪里,因为它似乎应该工作。我总是可以使用Objective-C版本,但感觉就像绕过这个问题。

enter image description here

func adtsDataForPacketLength(packetLength: Int) -> NSData {
    let adtsLength = 7
    let profile = 2
    let freqIdx = 4
    let chanCfg = 1
    let fullLength = adtsLength + packetLength;

    var packet = [UInt8]()
    packet.append(UInt8(0xFF))
    packet.append(UInt8(0xF9))
    packet.append(UInt8(((profile-1)<<6) + (freqIdx<<2) + (chanCfg>>2)))
    packet.append(UInt8(((chanCfg&3)<<6) + (fullLength>>11)))
    packet.append(UInt8((fullLength&0x7FF) >> 3))
    packet.append(UInt8(((fullLength&7)<<5) + 0x1F))
    packet.append(0xFC)
    return NSData(bytes: packet, length: packet.count)
}

0 个答案:

没有答案