我有一个正在创建的 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);