我收到“源路径为零”错误,但应该位于源路径的 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'
我错过了什么?