Save and Load

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)