我从Tuaw的一些示例代码中获取了一些代码,它可能已经过时了三个版本 ;) 编译器发出一个警告,说这种方法已被弃用,但我在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];