Storing NSArray or NSDictionary in keychainWrapper on IOS

keychainWrapper provides a mechanism for storing NSString

(like passwords).

Can I save NSArray

or NSDictionary

in keychainWrapper

?

+3


source to share


1 answer


You can use NSKeyedArchiver

and NSKeyedUnarchiver

, and if you have custom objects stored in a dictionary array, make sure the class implements the protocol NSCoding

.

NSData * encodedData = [NSKeyedArchiver archivedDataWithRootObject:array];

      

Then you can convert NSData to NSString using base64 encoding http://www.cocoawithlove.com/2009/06/base64-encoding-options-on-mac-and.html



for unarchiving it just goes backwards, use get NSData

from base64 NSString

and use unarchiver

NSArray *array = [NSKeyedUnarchiver unarchiveObjectWithData:data];

      

+7


source







All Articles