如何在Swift中设置CMutablePointer <ObjCBool​​>为false?

基本上我在Swift中使用AssetsLibrary框架,我怎么修改停止指针的值为NO / False / 0(我甚至不知道应该除了什么值)?

self.library.enumerateGroupsWithTypes(ALAssetsGroupType(ALAssetsGroupSavedPhotos), usingBlock: {(group: ALAssetsGroup!, stop: CMutablePointer<ObjCBool>) in }, failureBlock: {(error: NSError!) in }) 

我应该能够访问的价值,并用unsafePointer修改它,但我似乎无法正确地写封闭。

这相当于*stop = YES;

 stop.withUnsafePointer { $0.memory = true } 

为了使它更简洁,你可以做这样的事情:

 operator infix <- {} @infix func <- <T>(ptr: CMutablePointer<T>, value: T) { ptr.withUnsafePointer { $0.memory = value } } 

然后上面的行变成这样:

 stop <- true 

不知道这是build议的风格,但…

(您可以从/ = - + * % < > ! & | ^ . ~select字符来创build自定义运算符 。)

从Xcode 6 beta 4开始,你现在可以做到:

 stop.memory = true 

或者,正如holex指出的那样 ,您可以:

 stop.initialize(true)