美文网首页
iOS将网络请求数据写入磁盘(plist)

iOS将网络请求数据写入磁盘(plist)

作者: AnderQZ | 来源:发表于2019-07-25 17:43 被阅读0次
如何将网络请求数据以plist文件方式写入磁盘?

代码如下:

NSString *docPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES).lastObject;
    NSString *filePath = [docPath stringByAppendingPathComponent:@"/FileName.plist"];
    BOOL exist = [[NSFileManager defaultManager] fileExistsAtPath:filePath];
    if (!exist) {
        [[NSFileManager defaultManager] createFileAtPath:filePath contents:nil attributes:nil];
    }
    BOOL isSaved = [needToSaveData writeToFile:filePath atomically:YES]; //needToSaveData:需要存储的数据
    if (isSaved) {
        NSLog(@"Save success!!!");
    } else {
        NSLog(@"Save fail~");
    }

如果Log打印显示Save success!!!即表示写入成功。
文件存储在Document目录下的。

相关文章

网友评论

      本文标题:iOS将网络请求数据写入磁盘(plist)

      本文链接:https://www.haomeiwen.com/subject/hrckrctx.html