V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
WildCat
V2EX  ›  Swift

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

  •  
  •   WildCat · 2014-10-06 17:35:45 +08:00 · 6151 次点击
    这是一个创建于 3461 天前的主题,其中的信息可能已经有所发展或是发生改变。
    在用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行。

    感谢。

    .js
    4 条回复    2014-10-07 09:00:11 +08:00
    timonwong
        1
    timonwong  
       2014-10-06 18:55:52 +08:00
    WildCat
        2
    WildCat  
    OP
       2014-10-06 21:59:48 +08:00
    @timonwong 不行,IDE就报错的。

    'vImage_Buffer' is not convertible to 'UnsafePointer<vImage_Buffer>'
    timonwong
        3
    timonwong  
       2014-10-07 08:39:11 +08:00   ❤️ 1
    @WildCat
    func takesAMutablePointer(x: UnsafeMutablePointer<Float>) { /*...*/ }
    var x: Float = 0.0
    takesAMutablePointer(&x)
    WildCat
        4
    WildCat  
    OP
       2014-10-07 09:00:11 +08:00
    @timonwong 不行的,我用的这个方法就是无法调用
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5652 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 06:31 · PVG 14:31 · LAX 23:31 · JFK 02:31
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.