ios - Swift Cannot Assign to immutable value of type NSData -


this question has answer here:

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" } 

Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -