【发布时间】:2010-06-02 03:54:19
【问题描述】:
我有一些来自 Tuaw 的示例代码,可能是 3 个旧版本;) 编译器发出警告说该方法已被弃用,但我没有看到 SDK 文档中提到的内容。如果不推荐使用,则必须有替代方法或替换方法。有谁知道这个方法的替代品是什么?
具体代码为:
NSArray *crayons = [[NSString stringWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"crayons" ofType:@"txt"]] componentsSeparatedByString:@"\n"];
修改后的代码(在离散的白痴步骤中 - 并且没有错误处理)是:
NSError *error;
NSString *qs = [[NSBundle mainBundle] pathForResource: @"crayons" ofType: @"txt"];
NSString *ps = [[NSString alloc] stringWithContentsOfFile:qs encoding:NSUTF8StringEncoding error: &error];
NSArray *crayons = [[NSArray alloc] arrayWithContentsOfFile: ps];
【问题讨论】: