我现在很紧张,因为我要测试的应用找不到配置文件。
以下代码无法加载我的文件并返回错误字符串:“操作无法完成。(Cocoa 错误 260。)”,谷歌将其翻译为“读取错误(没有这样的文件)”。
-(id) initFromPath:(NSString *)path
{
NSError **e;
NSData *d = [NSData dataWithContentsOfFile:path options:NSDataReadingMapped error:e];
if(e != nil)
{
NSLog(@"%@", [*e localizedDescription]);
}
[self initFromData:d];
return self;
}
... //snip
[MyClass initFromPath:@"config.txt"];
我是 XCode 新手,所以我可能在设置项目时遗漏了一些步骤。到目前为止,我所做的只是将“config.txt”添加到项目模板为我设置的 Resources 文件夹中。
一如既往,我们将不胜感激任何帮助。谢谢!
最佳答案
您是否从 NSBundle 获取路径?你应该有类似 [[NSBundle mainBundle] pathForResource:@"config" ofType:@"txt"]
的输出进入你的initFromPath:
方法。
关于ios - 无法在 iOS 应用程序中加载文件; cocoa 错误260,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6685541/