您的位置:首页 > 移动开发 > Objective-C

NSUserDefaults:Attempt to insert non-property value Objective C

2014-09-04 22:28 393 查看
问题:

Attempt to set a non-property-list object{...}as an NSUserDefaults value for key shop.

解决办法:

if you don't want to bother about ensuring all your dictionary values are the property list types, then you can simply convert the dictionary into NSData,

NSUserDefaults *def = [NSUserDefaults standardUserDefaults];
[def setObject:[NSKeyedArchiver archivedDataWithRootObject:self.myDictionary] forKey:@"MyData"];
[def synchronize];
[/code]
And to get back into a dictionary from sandbox:

NSUserDefaults *def = [NSUserDefaults standardUserDefaults];
NSData *data = [def objectForKey:@"MyData"];
NSDictionary *retrievedDictionary = [NSKeyedUnarchiver unarchiveObjectWithData:data];
self.myDictionary = [[NSDictionary alloc] initWithDictionary:retrievedDictionary];
[/code]
Hope this helps someone.

参考:

http://stackoverflow.com/questions/15857408/attempt-to-insert-non-property-value-objective-c

http://stackoverflow.com/questions/23186021/nsuserdefaults-setobjectforkey-attempt-to-insert-non-property-list-object
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
相关文章推荐