所以我在尝试实现时遇到了一个异常,NSKeyedUnarchiver
因为我试图用NSUsersDefaults
. 因为我不断收到一个错误,说我有非属性,所以我决定将它们存档到NSData
. 现在我收到此错误:“无法理解的存档”。
这是我归档的方式(我已经测试了所有对象都为空,但它们都不是):
NSMutableArray *array = [[NSMutableArray alloc] initWithArray:anotherArray];
for (int i = 0; i < array.count; i++) {
CustomObj *obj = [array objectAtIndex:i];
NSData *newdata = [NSKeyedArchiver archivedDataWithRootObject:obj];
[array replaceObjectAtIndex:i withObject:newdata];
}
NSArray *newArray = [[NSArray alloc] initWithArray:array];
[coder setObject:newArray forKey:@"key"];
这是我取消归档的方式(再次测试所有内容是否为空):
if (!arrayM) { arrayM = [[NSMutableArray alloc] init]; NSLog(@"initialized"); }
else {
for (int i = 0; i < arrayM.count; i++) {
NSData *data = [arrayM objectAtIndex:i];
--> The exception happens here: CustomObj *obj = [NSKeyedUnarchiver unarchiveObjectWithData:data];
[arrayM replaceObjectAtIndex:i withObject:obj];
}
}