Skip to content

Instantly share code, notes, and snippets.

@dialektike
Created October 12, 2015 09:35
Embed
What would you like to do?
from String to NSData, from NSData to String
var swift_string = "lorem ipsum dolor sit amet"
// from String to NSData
let data = swift_string.dataUsingEncoding(NSUTF8StringEncoding)
print(data)
// from NSData to String
var out: String = String(data:data!, encoding:NSUTF8StringEncoding)!
print(out) // print "lorem ipsum dolor sit amet"
@dialektike
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment