当前位置: 代码迷 >> Iphone >> iphone序列化资料
  详细解决方案

iphone序列化资料

热度:112   发布时间:2016-04-25 06:25:13.0
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;
}

  相关解决方案