我们如何使用KeychainItemWrapper类(ARC)保存NSArray [英] How can we save NSArray using KeychainItemWrapper class(ARC)
本文介绍了我们如何使用KeychainItemWrapper类(ARC)保存NSArray的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想保存 NSArray
使用 KeychainItemWrapper
class
I want to save NSArray
using KeychainItemWrapper
class
我已经知道在阅读这个问题后我们可以存储 NSDictionary
I have come to know that we can store the NSDictionary
after reading 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];
但它在我们设置对象的最后一行崩溃。
But it is crashing at last line where we are setting object.
Erro Logs:
Erro Logs:
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'
需要帮助。
推荐答案
我有想法。你可以试试这个。你必须 #importSBJsonWriter.h
i have idea. you can try this. you must #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"];
这篇关于我们如何使用KeychainItemWrapper类(ARC)保存NSArray的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文