我自己往xcode添加了一個sql文件,添加在類似下面Pods/Frameworks/的目錄中,但是代碼執行的時候貌似找不到我自己加的文件
- (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]);
}
}
}