iphone序列化文件

#pragma -
#pragma 序列化列表
+ (BOOL)saveMatchListToFile:(NSArray*)newMathcList {
    NSString *mathcListFile = [[PlayViewController getLocalMatchList] stringByAppendingFormat:@"matchList.arch", nil];
    return [NSKeyedArchiver archiveRootObject:newMathcList toFile:mathcListFile];
}

+ (NSMutableArray*)getMatchListFromFile {
    NSString *matchListFile = [[PlayViewController getLocalMatchList] stringByAppendingFormat:@"matchList.arch", nil];
    return [NSKeyedUnarchiver unarchiveObjectWithFile:matchListFile];
}

+ (NSString*)getLocalMatchList {
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
   
    NSString *documentsDirectory = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"tdata"];
   
    BOOL isDirectory = YES;
    if (![[NSFileManager defaultManager] fileExistsAtPath:documentsDirectory isDirectory:&isDirectory]) {
        NSError *error = nil;
        [[NSFileManager defaultManager] createDirectoryAtPath:documentsDirectory withIntermediateDirectories:YES attributes:nil error:&error];
        if (error) {
            NSLog(@"------ create directory error : %@", error);
        }
    }
   
    return documentsDirectory;
}

你可能感兴趣的:(iPhone)