gpt4 book ai didi

ios - 将 plist 文件打印到 NSLog

转载 作者:行者123 更新时间:2023-11-28 22:46:15 25 4
gpt4 key购买 nike

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

最佳答案

您只差一步。您需要将 NSData 转换为字符串,然后就可以开始了:

NSData *data = [NSPropertyListSerialization 
dataFromPropertyList:root
format:NSPropertyListXMLFormat_v1_0
errorDescription:nil];

NSString *string = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];

NSLog(@"%@", string);

关于ios - 将 plist 文件打印到 NSLog,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13163686/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com