【发布时间】:2013-10-01 06:50:34
【问题描述】:
我想使用KeychainItemWrapper 类保存NSArray
读了This Question后才知道可以存储NSDictionary
但它不起作用
这是我目前所做的
NSArray *myArray = [[NSArray alloc]initWithObjects:@"Hello1",@"Hello2",@"Hello3",@"Hello4", nil];
NSDictionary *myDic = [[NSDictionary alloc]initWithObjectsAndKeys:myArray, @"arrayKey", nil];
NSString *error;
NSData *dictionaryRep = [NSPropertyListSerialization dataFromPropertyList:myDic format:NSPropertyListXMLFormat_v1_0 errorDescription:&error];
KeychainItemWrapper *keychain =
[[KeychainItemWrapper alloc] initWithIdentifier:@"MyIdentifier" accessGroup:nil];
[keychain setObject:dictionaryRep forKey:(__bridge id)kSecValueData];
但它在我们设置对象的最后一行崩溃了。
错误日志:
2013-10-01 12:16:47.590 stackoverflowtry[3883:a0b] -[__NSCFData dataUsingEncoding:]: unrecognized selector sent to instance 0xa1686a0
2013-10-01 12:16:47.593 stackoverflowtry[3883:a0b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFData dataUsingEncoding:]: unrecognized selector sent to instance 0xa1686a0'
需要帮助。
【问题讨论】:
-
请告诉我如何保存 NSDictionary 或 NSArray,两者都对我有用..
-
为什么你使用“(__bridge id)kSecValueData”作为存储字典的键?,你记录这个值来检查值吗?
-
@josh : (__bridge id)kSecValueData 是 KeychainItemWrapper.m 文件中的预定义键...我不认为我们被允许使用用户定义的键...如果我只需传递 NSString 而不是 dictionaryRep。
标签: ios objective-c ipad keychainitemwrapper