swiftnsvalue

How to convert IMP to NSValue with Swift?


enter image description here

I want convert the implementation to NSValue, but it's err.

In Objective-C, can use this line to convert:

[NSValue valueWithPointer:implementation]

but in Swift, how to convert?


Solution

  • As it says, it needs an UnsafePointer, not a COpaquePointer. So convert it:

    let impValue = NSValue(pointer: UnsafePointer(imp))