0

「ソース パスが nil です」というエラーが表示されますが、ソース パスにあるはずの plist がバンドル リソースにあります。

コード:

{NSError *error;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = paths[0];
NSString *path = [documentsDirectory stringByAppendingPathComponent:@"gHaiku413.plist"];
NSFileManager *fileManager = [NSFileManager defaultManager];
if (![fileManager fileExistsAtPath: path]) {
    NSString *bundle = [[NSBundle mainBundle] pathForResource:@"gHaiku413" ofType:@"plist"];
            NSLog(@"%@",bundle);
    [fileManager copyItemAtPath:bundle toPath: path error:&error];

}

Build Phases に移動して Copy Bundle Resources を見ると、gHaiku413.plist は間違いなくそこにありますが、得られる結果は次のとおりです。

//This is the output of NSLog(@"%@",bundle):
2013-09-18 16:49:22.728 GHaiku[39389:a0b] (null)
2013-09-18 16:49:22.733 GHaiku[39389:a0b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSFileManager copyItemAtPath:toPath:error:]: source path is nil'

私は何が欠けていますか?

4

1 に答える 1

0

これが質問の単なるタイプミスなのか、それとも実際の問題なのかはわかりませんが、ファイルを[[NSBundle mainBundle] pathForResource:@"gHaiku413" ofType:@"plist"];探して、間違いなくそこにあると言いました。これらは異なるファイル名です。gHaiku413.plistgHaiku.plist

更新:コメントで議論した結果、次のようになりました。

  1. 非常にクリーンなビルドを試してください:cmd ⌘</kbd>+alt ⌥</kbd>+Shift ⇧</kbd>+K and failing that, an uber-clean build:
    • Close Xcode
    • Delete both xcuserdata directories: MyProject.xcodeproj/xcuserdata and MyProject.xcodeproj/project.xcworkspace/xcuserdata
    • Delete the ~/Library/Developer/Xcode/DerivedData directory
    • Restart Xcode
    • Build
  2. シミュレーターのコンテンツと設定をリセットする
于 2013-09-18T22:08:46.327 に答える