![](/img/trans.png)
[英]Unable to copy sqlite file from app bundle to documents directory: getting (Cocoa error 260)
[英]Unable to load file in iOS app; Cocoa error 260
我現在正在拔頭發,因為我要測試的應用程序找不到配置文件。
以下代碼無法加載我的文件並返回錯誤字符串:“無法完成操作。(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”添加到項目模板為我設置的資源文件夾中。
與往常一樣,我們將不勝感激任何幫助。 謝謝!
您是否從 NSBundle 中獲取路徑? 您應該將[[NSBundle mainBundle] pathForResource:@"config" ofType:@"txt"]
類的 output 傳遞到您的initFromPath:
方法中。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.