Чтобы получить путь к файлу, который вы добавили в XCode, вы должны использовать pathForResource: ofType: с вашим mainBundle.
NSString *path = [[NSBundle mainBundle] pathForResource:@"yourDb" ofType:@"sqlite"];
Но вы не можете изменять файлы в mainBundle.Таким образом, вы должны скопировать его в другое место.Например, в библиотеку вашего приложения.
Вы можете сделать это так:
NSString *libraryPath = [NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES) lastObject];
NSString *targetPath = [libraryPath stringByAppendingPathComponent:@"yourDB.sqlite"];
if (![[NSFileManager defaultManager] fileExistsAtPath:targetPath]) {
// database doesn't exist in your library path... copy it from the bundle
NSString *sourcePath = [[NSBundle mainBundle] pathForResource:@"yourDb" ofType:@"sqlite"];
NSError *error = nil;
if (![[NSFileManager defaultManager] copyItemAtPath:sourcePath toPath:targetPath error:&error]) {
NSLog(@"Error: %@", error);
}
}