I added a sql file to xcode myself, and added it to a directory similar to Pods/Frameworks/ below , but when the code is executed, it seems that the file I added cannot be found
- (instancetype)initWithDatabaseFilename:(NSString *)dbFilename {
self = [super init];
if (self) {
self.databaseFilename = dbFilename;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
self.databasePath = [documentsDirectory stringByAppendingPathComponent:self.databaseFilename];
[self copyDatabaseIntoDocumentsDirectory];
}
return self;
}
- (void)copyDatabaseIntoDocumentsDirectory {
if (![[NSFileManager defaultManager] fileExistsAtPath:_databasePath]) {
NSString *sourcePath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:_databaseFilename];
NSError *error;
[[NSFileManager defaultManager] copyItemAtPath:sourcePath toPath:_databasePath error:&error];
if (error != nil) {
NSLog(@"error: %@", [error localizedDescription]);
}
}
}