无法恢复存档的文件内容

时间:2012-06-16 11:34:09

标签: objective-c nsdocument

呃......这有什么不对:

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;
}

...因为我的数组当然是空的(没有记录错误)

顺便说一下,在这段代码中只有一个键,但其他键稍后会添加。

谢谢!

0 个答案:

没有答案