美文网首页
Save and Load

Save and Load

作者: Nick_Zuo | 来源:发表于2017-02-27 22:30 被阅读15次

Save

    // Plist: Array and Dictionary
    NSArray *arr = @[ @"123", @1 ];
    
    // @param NSSearchPathDirectory: search path
    // @param NSSearchPathDomainMask: where to search
    // @param expandTilde: full path or NOT
    NSString *cachePath = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES)[0];
    
    NSString *filePath = [cachePath stringByAppendingPathComponent:@"arr.plist"];
    
    NSLog(@"%@", cachePath);
    
    [arr writeToFile:filePath atomically:YES];

Load

    NSString *cachePath = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES)[0];
    
    NSString *filePath = [cachePath stringByAppendingPathComponent:@"arr.plist"];
    
    NSArray *arr = [NSArray arrayWithContentsOfFile:filePath];
    NSLog(@"%@",arr);
    
//    for (id tmp in arr) {
//        NSLog(@"%@",tmp);
//    }

相关文章

网友评论

      本文标题:Save and Load

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