User User - 2 days ago 5
Swift Question

Printing NSData in Swift?

How do you output the value of

NSData
in Swift? Is it
NSLog
,
print
or
println
?

It seems I can just print the address of the object, and not the actual contents of it.

Thank-you

Answer

So after trying a number of recommendations around the site, this is what actually ended up working for me.

Swift 3

let string1 = String(data: jsonData, encoding: String.Encoding.utf8) ?? "Data could not be printed"
print(string1)

Swift 1

let string1 = NSString(data: jsonData, encoding: NSUTF8StringEncoding)
println(string1)
Comments