I have an IOS app with a watch extension. I use a read-only SQLite file with Core Data (which is already populated and not edited).
Accessing the file from the bundle resources works fine using this code.
- (NSURL *)storeURL{
NSString * databaseFileName = @"db.sqlite";
return [NSURL fileURLWithPath: [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent: databaseFileName]];
}
However, this code creates a new sqlite file and attach it to the NSPersistentStoreCoordinator:
- (NSURL *)applicationDocumentsDirectory {
return [[NSFileManager defaultManager] containerURLForSecurityApplicationGroupIdentifier:@"group.com.xxx.xxx"];
}
- (NSURL *)storeURL{
NSString * databaseFileName = @"db.sqlite";
NSURL * url = [self applicationDocumentsDirectory];
NSString * path = [url.absoluteString stringByAppendingPathComponent:databaseFileName];
path = [path stringByReplacingOccurrencesOfString:@"file:" withString:@"" options:NSLiteralSearch range:NSMakeRange(0, path.length)];
return [NSURL fileURLWithPath: path];
}
How do I add the SQLite file to a shared app group container in Xcode?