How to initialise a string from NSData in Swift -


i have been trying initialise string nsdata in swift.

in nsstring cocoa documentation apple saying have use this:

 init(data data: nsdata!, encoding encoding: uint) 

however apple did not include example usage or put init.

i trying convert following code objective-c swift

nsstring *string; string = [[nsstring alloc] initwithdata: data encoding: nsutf8stringencoding]; 

i have been trying lot of possible syntaxes such following (of course did not work):

var string:nsstring! string = init(data: foodata,encoding: nsutf8stringencoding) 

this how should initialize nsstring:

swift 2.x or older

let datastring = nsstring(data: foodata, encoding: nsutf8stringencoding) 

swift 3 or newer:

let datastring = nsstring(data: foodata, encoding: string.encoding.utf8.rawvalue) 

this doc explains syntax.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -