NSString initWithBytes using swift -
trying convert (working) objc code:
const uint8_t * buffer = ... nsstring * password = [[nsstring alloc] initwithbytes:buffer+28 length:buffer[27] encoding:nsutf8stringencoding];
tried:
let buffer: [byte] = ... var password = nsstring(bytes: buffer+28, length: int(buffer[27]), encoding: nsutf8stringencoding)
but crashes sourcekitservice immediately, , compiler if seek compile.
i suspect it's maybe converting pointers?
if need convert byte array nsstring, build
nsstring(bytes: buffer, length: buffer.length, encoding: nsutf8stringencoding)
if need pointer advance etc, convert unsafepointer following:
nsstring(bytes: unsafepointer<byte>(buffer) + 28, length: int(buffer[27]), encoding: nsutf8stringencoding)
swift nsstring
No comments:
Post a Comment