我有一个我正在创建的plist文件,但是我没有写入文件,而是将其内容作为字符串打印到NSLog:
NSMutableDictionary* root = [NSMutableDictionary dictionaryWithCapacity:1];
NSMutableArray* puzzle = [NSMutableArray arrayWithCapacity: [self.puzzlePieces count] ];
root[@"puzzle"] = puzzle;
[self.puzzlePieces enumerateObjectsUsingBlock:^(KTPuzzlePiece* piece, NSUInteger idx, BOOL *stop) {
NSMutableDictionary* pieceInfo = [piece.pieceInfo mutableCopy];
pieceInfo[@"x"] = [NSNumber numberWithFloat: piece.position.x];
pieceInfo[@"y"] = [NSNumber numberWithFloat: piece.position.y];
[puzzle addObject:pieceInfo];
}];
NSData *data = [NSPropertyListSerialization dataFromPropertyList:root
format:NSPropertyListXMLFormat_v1_0
errorDescription:nil];
但是,以下输出十六进制值
NSLog(@"Data: %@", data);
答案 0 :(得分:2)
你只是错过了一步。你需要将你的NSData转换成一个字符串,你应该好好去:
NSData *data = [NSPropertyListSerialization
dataFromPropertyList:root
format:NSPropertyListXMLFormat_v1_0
errorDescription:nil];
NSString *string = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
NSLog(@"%@", string);