0
因此,我已经编写了这种便捷方法作为从属性列表创建NSDictionary不是如容易的问题的解决方案,例如从文件/ Web资源。虽然我可能解析这个使用NSXMLParser,或改变我的服务器发送数据的方式(json,无论),这是目前不关心,而我担心的是,这种方法是无可否认的缓慢,容易发生碰撞,因为我不要使用rand()来确定.plist的文件名。在NSString中从PLIST创建字典
那么,有可能让这个更快吗?我需要确保该文件不存在于应用程序的删除之间,因此使用/ tmp。
+ (NSDictionary *)dictionaryFromPropertyListString:(NSString *)stringToParse
{
NSLog(@"dictionaryFromPropertyListString: %@", stringToParse);
NSString *newFilePath = [NSTemporaryDirectory() stringByAppendingString:@"/Stuff.plist"];
[stringToParse writeToFile:newFilePath atomically:YES encoding:NSASCIIStringEncoding error:nil];
NSDictionary *dictionaryToReturn = [NSDictionary dictionaryWithContentsOfFile:newFilePath];
NSLog(@"returned dictionary: %@", [dictionaryToReturn descriptionInStringsFileFormat]);
return dictionaryToReturn;
}