ios解檔歸檔2

    NSArray *array = [NSArray arrayWithObjects:@"one", @"two", @"three", nil];

    NSString *filePath = [NSHomeDirectory() stringByAppendingPathComponent:@"data"];

    //多對象歸檔

    NSMutableData *data = [NSMutableData data];

//    NSKeyedArchiver *archiver = [[NSKeyedArchiver alloc] initForWritingWithMutableData:data];

//    [archiver encodeObject:array forKey:@"array"];

//    [archiver encodeObject:@12 forKey:@"age"];

//    [archiver encodeObject:@"hh" forKey:@"name"];

//    [archiver finishEncoding];

//    [data writeToFile:filePath atomically:YES];

    

    //多對象解檔

    NSMutableData * getData = [[NSMutableData alloc] initWithContentsOfFile:filePath];

    NSKeyedUnarchiver * unarchiver = [[NSKeyedUnarchiver alloc] initForReadingWithData:getData];

    NSLog(@"%@",[unarchiver decodeObjectForKey:@"array"]);

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章