UnsafePointer<UInt8> initializer in Swift 3

╄→гoц情女王★ 提交于 2019-12-03 05:39:58
  1. In Swift 3, you cannot init an UnsafePointer using an UnsafeRawPointer.

    You can use assumingMemoryBound(to:) to convert an UnsafeRawPointer into an UnsafePointer<T>. Like this:

    var ptr = data.bytes.assumingMemoryBound(to: UInt8.self)
    
  2. Use debugDescription or distance(to:) to compare two pointer.

    while(ptr.debugDescription < endPtr.debugDescription)
    

    or

    while(ptr.distance(to:endPtr) > 0)
    

May have recently changed to just this, without the ".bytes." part:

var p: UnsafePointer = data.assumingMemoryBound(to: UInt8.self)

from the original:

var p = UnsafePointer<UInt8>(data.bytes)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!