0

plist ファイルを作成しようとしています。しかし、 [NSFileManager copyItemAtPath:toPath:error:] でエラーが発生します: ソース パスが nil です

誰かがなぜそれが起こっているのか知っていますか? どうもありがとうございました..

AppDelegate.h :

NSError*error;
NSArray*pathes=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString*documentDirectory=[pathes objectAtIndex:0];//first dir in app dir.
NSString*path=[documentDirectory stringByAppendingPathComponent:@"data.plist"];

NSFileManager*filemanager=[NSFileManager defaultManager];
if(![filemanager fileExistsAtPath:path])
{
    NSString*bundle=[[NSBundle mainBundle]pathForResource:@"data" ofType:@"plist"];//check if plist file exist;



    [filemanager copyItemAtPath:bundle toPath:path error:&error];
    NSMutableDictionary*data=[[NSMutableDictionary alloc]initWithContentsOfFile:path];
    NSArray*arr=[[NSArray alloc]init];
    [data setObject:arr forKey:@"arr"];
    [data writeToFile:path atomically:YES];
}
4

1 に答える 1

0

- [NSBundle pathForResource:ofType:]nil要求されたファイルが存在しない場合に戻ります。アプリバンドルに実際にが含まれていることを確認してくださいdata.plist

于 2013-01-29T15:42:20.103 に答える