Quantcast
Channel: User Sargis - Stack Overflow
Viewing all articles
Browse latest Browse all 37

Answer by Sargis for How to import sqlite file into app's document directory in ios?

$
0
0

// Returns the persistent store coordinator for the application.// If the coordinator doesn't already exist, it is created and the application's store added to it.

- (NSPersistentStoreCoordinator *)persistentStoreCoordinator{if (_persistentStoreCoordinator != nil){    return _persistentStoreCoordinator;}NSURL *storeURL = [[self applicationDocumentsDirectory] URLByAppendingPathComponent:@"yourSqlite.sqlite"];NSString *sourcePath = [[NSBundle mainBundle] pathForResource:@"yourSqlite.sqlite" ofType:nil];NSString *documentsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];NSError *error = nil;if  (![[NSFileManager defaultManager] fileExistsAtPath:[documentsDirectory stringByAppendingPathComponent:@"yourSqlite.sqlite"] ]) {    if([[NSFileManager defaultManager] copyItemAtPath:sourcePath toPath:[documentsDirectory stringByAppendingPathComponent:@"yourSqlite.sqlite"] error:&error]){        NSLog(@"Default file successfully copied over.");    } else {        NSLog(@"Error description-%@ \n", [error localizedDescription]);        NSLog(@"Error reason-%@", [error localizedFailureReason]);    }}_persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]];if (![_persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:nil error:&error]){    NSLog(@"Unresolved error %@, %@", error, [error userInfo]);    abort();}return _persistentStoreCoordinator;}

Viewing all articles
Browse latest Browse all 37

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>