我有一个UInt32?
变量,我需要获取该值,但使用!
会引发错误:fatal error: unexpectedly found nil while unwrapping an Optional value
。不,我知道这不是零。
static func checkBitrate(filePath: String) -> Bool {
let audioURL = NSURL.fileURLWithPath(filePath)
var audioFile : AudioFileID = nil
var theErr: OSStatus? = nil
let hint: AudioFileTypeID = 0
theErr = AudioFileOpenURL(audioURL, Int8(kAudioFileReadPermission), hint, &audioFile)
if (theErr != OSStatus(noErr)) {
return false
}
var outDataSize: UInt32 = 0
var isWritable: UInt32 = 0
theErr = AudioFileGetPropertyInfo(audioFile, UInt32(kAudioFilePropertyBitRate), &outDataSize, &isWritable)
if (theErr != OSStatus(noErr)) {
return false
}
var bitrate: UInt32? = nil
theErr = AudioFileGetProperty(audioFile, UInt32(kAudioFilePropertyBitRate), &outDataSize, &bitrate)
if (theErr != OSStatus(noErr)) {
return false
}
println("Bitrate value: \(bitrate)")
let br = bitrate!
//return br == 192000
return false
}
错误在行let br = bitrate!
处抛出。
我有点迷茫,我做错了什么?
答案 0 :(得分:1)
您只需要初始化var
var bitrate: UInt32 = 0