[英]Storing NSArray or NSDictionary in keychainWrapper in IOS
keychainWrapper provides the mechanism for storing a NSString
(like passwords). keychainWrapper提供了存储NSString
(如密码)的机制。
Can I also store NSArray
or NSDictionary
in keychainWrapper
? 我还可以在keychainWrapper
存储NSArray
或NSDictionary
吗?
You can use NSKeyedArchiver
and NSKeyedUnarchiver
, and if you have custom objects stored in the array of dictionary, make sure that class implements the NSCoding
protocol. 您可以使用NSKeyedArchiver
和NSKeyedUnarchiver
,如果您有自定义对象存储在字典数组中,请确保该类实现NSCoding
协议。
NSData * encodedData = [NSKeyedArchiver archivedDataWithRootObject:array];
You can then convert NSData to NSString using base64 encoding http://www.cocoawithlove.com/2009/06/base64-encoding-options-on-mac-and.html 然后,您可以使用base64编码将NSData转换为NSString http://www.cocoawithlove.com/2009/06/base64-encoding-options-on-mac-and.html
for unarchiving it's just going backwards,use get NSData
from the base64 NSString
and use the unarchiver 对于unarchiving它只是向后,使用从base64 NSString
获取NSData
并使用unarchiver
NSArray *array = [NSKeyedUnarchiver unarchiveObjectWithData:data];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.