如何设置CMutablePointer< ObjCBool​​>斯威夫特的假? [英] How to set CMutablePointer<ObjCBool> to false in Swift?

查看:98
本文介绍了如何设置CMutablePointer< ObjCBool​​>斯威夫特的假?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Basically I'm using the AssetsLibrary frameworks in Swift, how could I modify the value of the stop pointer to NO/False/0 (I don't even know what value it should except) ?

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

},
failureBlock: {(error: NSError!) in

})

我应该能够访问该值并使用unsafePointer修改它,但我似乎无法正确编写闭包。

I should be able to access the value and modify it with unsafePointer but I can't seems to be able to write the closure correctly.

推荐答案

这相当于 * stop = YES;

stop.withUnsafePointer { $0.memory = true }

为了使它更简洁,您可以执行以下操作:

To make it more succinct, you could do things like:

operator infix <- {}

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

然后上面的行就变成了这样:

and then the line above becomes simply this:

stop <- true

不确定这是否是推荐的风格,但是......

Not sure if that's recommended style, though...

(您可以从 / = - + *%<中选择字符>!& | ^。〜创建自定义运算符。 )

(You can choose characters from / = - + * % < > ! & | ^ . ~ to create custom operators.)

这篇关于如何设置CMutablePointer&lt; ObjCBool​​&gt;斯威夫特的假?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆