objective c - How to convert a type of "any" in kind "UnsafeMutablePointer<Int16>" in a swift 3 -


i updated xcode latest beta , there such problem. before code worked in objective-c:

short * pointers = (short *)[[params valueforkey:@"pointers"] pointervalue]; 

then translated part of code on swift language:

let pointers = unsafemutablepointer<int16>(((params["pointers"] anyobject).pointervalue)!) 

here, too, good. but code not working on swift 3. tell how can implement on swift 3. thank you!

the correct way of converting pointer uint16 wrapped in nsvalue unsafemutablepointer<int16> in swift 3 is

if let ptr = value.pointervalue {     let u16ptr = ptr.assumingmemorybound(to: uint16.self)     // ... } else {     // pointer nil } 

in case should be

if let ptr = (params["pointers"] as? nsvalue)?.pointervalue {     let u16ptr = ptr.assumingmemorybound(to: uint16.self)     // ... } else {     // value not exist, not `nsvalue`, or pointer nil } 

Comments