Swift和Boolean

时间:2014-06-08 17:49:02

标签: core-audio swift

函数AUGraphIsInitialized的定义如下:

func AUGraphIsInitialized(inGraph: AUGraph, outIsInitialized: CMutablePointer<Boolean>) -> OSStatus

所以,你这样称呼它:

var status : OSStatus = OSStatus(noErr)
var outIsInitialized:Boolean = 0
status = AUGraphIsInitialized(self.processingGraph, &outIsInitialized)

有效。但你怎么检查呢?

布尔值定义为CUnsignedChar(在MacTypes.h中)

所以,你不能这样做:

if outIsInitialized {
    // whatever
}

你无法施放它(找不到超载......)

var b:Bool = Bool(outIsInitialized)

或使用Swift&#34; as&#34;

var b:Bool = outIsInitialized as Bool

所以,我的问题是:你如何在Swift中使用Boolean?

1 个答案:

答案 0 :(得分:3)

C表示布尔值true,非零值,false表示零值,因此您只需针对outIsInitialized测试0

if outIsInitialized != 0 {
    // outIsInitialized is true
}