Swift 中如何使用 UnsafePointer(方法传参)

2014-10-06 17:35:45 +08:00
 WildCat
在用Swift重写一个开源边栏菜单,但是遇到个问题,就是

vImageBoxConvolve_ARGB8888(&effectInBuffer, &effectOutBuffer, NULL, 0, 0, (uint32_t)radius, (uint32_t)radius, 0, kvImageEdgeExtend);

这样的语句,用Swift不知道怎么写。虽然搜到了一个类似问题 http://stackoverflow.com/questions/24110769/how-to-correctly-initialize-an-unsafepointer-in-swift ,但是 withUnsafePointer(&arg: T, body: (UnsafePointer<T>) -> Result) 这里有个闭包不知道如何写。


https://github.com/rnystrom/RNFrostedSidebar/blob/master/RNFrostedSidebar.m
第99行。

感谢。

https://gist.github.com/imWildCat/17f47926c453a1ff7a62.js
6171 次点击
所在节点    Swift
4 条回复
timonwong
2014-10-06 18:55:52 +08:00
WildCat
2014-10-06 21:59:48 +08:00
@timonwong 不行,IDE就报错的。

'vImage_Buffer' is not convertible to 'UnsafePointer<vImage_Buffer>'
timonwong
2014-10-07 08:39:11 +08:00
@WildCat
func takesAMutablePointer(x: UnsafeMutablePointer<Float>) { /*...*/ }
var x: Float = 0.0
takesAMutablePointer(&x)
WildCat
2014-10-07 09:00:11 +08:00
@timonwong 不行的,我用的这个方法就是无法调用

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/137290

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX