【问题标题】:Archiving on iOS using NSKeyedArchiver使用 NSKeyedArchiver 在 iOS 上归档
【发布时间】:2012-06-06 22:35:13
【问题描述】:

我希望我的应用解压缩并处理 zip 文件的内容。

我正在尝试以 Cocoa 方式执行此操作,而不使用外部库,所以我转向 NSKeyedUnarchiver,这是我的代码:

-(void) unarchive{

    NSString *outputDirectory = [[NSHomeDirectory() stringByAppendingString:@"/Documents/"] stringByAppendingString:@"TheNewFolderName/"];
    NSLog(@"Output Directory: %@", outputDirectory);

    //MyArchive.zip is the filename of the zip file I placed in Xcode
    NSData *theArchive = [NSKeyedUnarchiver unarchiveObjectWithFile:@"MyArchive.zip"];

    NSError *error;
    [theArchive writeToFile:outputDirectory options:NSDataWritingAtomic error:&error];

    NSLog(@"theArchive is %@", theArchive);

这会打印“theArchive is null”!我做错什么了..?

【问题讨论】:

    标签: ios cocoa-touch zip nskeyedarchiver


    【解决方案1】:

    NSKeyedArchiverNSKeyedUnarchiver 用于归档和取消归档应用程序中的对象(NSObject 子类,有一定的限制)。恐怕您不能将它与 zip 文件一起使用。

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-10-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多