UnsafePointer initializer in Swift 3

前端 未结 3 467
挽巷
挽巷 2021-02-05 04:09

I have a receipt validation class that is deprecated since Swift 3 has released. I fixed some issues, but I still have many ...

Here is the GitHub source code I used : h

3条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-02-05 05:01

    1. In Swift 3, you cannot init an UnsafePointer using an UnsafeRawPointer.

      You can use assumingMemoryBound(to:) to convert an UnsafeRawPointer into an UnsafePointer. 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)
      

提交回复
热议问题