呃......这有什么不对:
SAVING:
- (NSData *)dataOfType:(NSString *)typeName error:(NSError **)outError
{
NSMutableData *data = [NSMutableData data];
NSKeyedArchiver *archiver = [[NSKeyedArchiver alloc] initForWritingWithMutableData:data];
[archiver encodeObject:[cardArrayController arrangedObjects] forKey:@"ATXTCards"];
[archiver finishEncoding];
return data;
}
读:
- (BOOL)readFromData:(NSData *)data ofType:(NSString *)typeName error:(NSError **)outError
{
NSKeyedUnarchiver *unarchiver = [[NSKeyedUnarchiver alloc] initForReadingWithData:data];
[cardArrayController addObjects: [unarchiver decodeObjectForKey:@"ATXTCards"]];
[unarchiver finishDecoding];
[cardArrayController setSelectionIndex:0];
return YES;
}
...因为我的数组当然是空的(没有记录错误)
顺便说一下,在这段代码中只有一个键,但其他键稍后会添加。
谢谢!