我想使用NSArray类保存KeychainItemWrapper
我已经知道我们可以在阅读了NSDictionary之后存储This Question
但它不起作用
,这就是我到目前为止所做的,
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'需要帮助。
发布于 2013-10-01 09:39:42
我有个主意。你可以试试这个。你必须#import "SBJsonWriter.h"
NSArray *myArray = [[NSArray alloc]initWithObjects:@"Hello1",@"Hello2",@"Hello3",@"Hello4", nil];
NSDictionary *myDic = [[NSDictionary alloc]initWithObjectsAndKeys:myArray, @"arrayKey", nil];
KeychainItemWrapper *keychain =
[[KeychainItemWrapper alloc] initWithIdentifier:@"MyIdentifier" accessGroup:nil];
SBJsonWriter *jsonWriter = [[SBJsonWriter alloc] init];
NSString *jsonString = @"";
jsonString = [jsonWriter stringWithObject:myDic];
[keychain setObject:jsonString forKey:(__bridge id)(kSecAttrDescription)];如果你想得到它
NSString *JsonString= [keychain objectForKey:(__bridge id)(kSecAttrDescription)];
NSArray *myArray= [[JsonString JSONValue] objectForKey:@"arrayKey"];https://stackoverflow.com/questions/19109739
复制相似问题