I'm trying to convert NSData generated from NSKeyedArchiver to an NSString so that I can pass it around and eventually convert it back to NSData. I have to pass this as a string (I'm using three20 URL passing). I've gone through various encodings, UTF8, ASCII, etc. and can't get anything to work. NSKeyedArchiver says that the NSData is formated as a property list: NSPropertyListBinaryFormat_v1_0.
Does anyone have any idea how I can convert this NSData to a String and back again? Size of the string isn't an issue.
Thanks
All you should have to do is something like this:
then to extract the data:
What you want is:
And then the other way around
You can add base64EncodedString and dataFromBase64String: with the NSData category available here NSData+Base64 but it is now included by default
iOS 9.2.1, Xcode 7.2.1, ARC enabled
Updated solution:
Encode to string:
Decode to data:
Note: This is very useful when working with keychain to store a dictionary of key/value pairs into kSecValueData.
Hope this helps someone! Cheers.