ios - Swift Cannot Assign to immutable value of type NSData -
this question has answer here:
- convert utf-8 encoded nsdata nsstring 6 answers
i have
let data = nsdata(bytes: &positionvalue, length: sizeof(uint8))
and
let datastring=nsstring(bytes: &data, length: sizeof(uint8), encoding: nsutf8stringencoding)
unfortunately compiler throws error @ second line, saying can't assign immutable value of type nsdata. how go converting original data
variable string encoding sutf8stringencoding
?
update: xcode 7.2 • swift 2.1.1
let myteststring = "hello world" // converting string nsdata if let mystringdata = myteststring.datausingencoding(nsutf8stringencoding) { // converting nsdata string let mystringfromdata = string(data: mystringdata, encoding: nsutf8stringencoding) ?? "hello world" }