In earlier versions of Swift I could convert NSData
to a UTF8 string thus:
let desc:String = String(data: requestData, encoding: NSUTF8StringEncoding)
(The documentation for NSString
's init(data:NSData,encoding:NSStringEncoding)
is here.)
In Swift 3 using Data
I would expect something like
let desc:String = requestData.description(usedEncoding: String.Encoding.utf8)
But that does not exist (Data
's documentation is here). What is the correct Swift 3 translation?
It's actually the same syntax
init?(data: Data, encoding: String.Encoding)
let desc = String(data: requestData, encoding: .utf8)
Don't annotate types the compiler can infer.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With