w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Convert NSString to NSDictionary and NSDictionary to NSString

What you want is:

id<nscoding> obj;

NSData * data     = [NSKeyedArchiver archivedDataWithRootObject:obj];
NSString * string = [data base64EncodedString];

And then the other way around

NSString * string;

NSData * data    = [NSData dataFromBase64String:string];
id<nscoding> obj = [NSKeyedUnarchiver unarchiveObjectWithData:data]

You can add base64EncodedString and dataFromBase64String: with the NSData category available here NSData+Base64

NSUTF8StringEncoding return nil when you try to encode something that is not data made of an utf8 string.





© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.