I'm trying to use configurations to manage transient entities in core data.
- First, i have created 2 coredata configurations named "Persistent" and "Transient".
- Then, i have created the entities and i have associated them with the right configuration depending on the entity is persistable or not.
- Finally, using the persistentStoreCoordinator, i have created one persistent store of type Sqlite and linked it to the "Persistent" configuration. I have also created a persistent store of type memory and linked it to the "Transient" configuration.
The test: i start the iphone simulator, my app starts successfully. I close the simulator and start sqlite3 on the database file. I list the tables ( .tables command) and what i can see is that some tables have been created for my transient entities => So, it doesnot work.
- (NSPersistentStoreCoordinator *)persistentStoreCoordinator
{
NSLog(@"++++++++ persistentStoreCoordinator");
if (_persistentStoreCoordinator != nil) {
return _persistentStoreCoordinator;
}
NSURL *persistStoreURL = [[self applicationDocumentsDirectory] URLByAppendingPathComponent:@"ProjectToDelete.sqlite"];
NSMutableDictionary *sqliteOptions = [NSMutableDictionary dictionary];
[sqliteOptions setObject:@"WAL" forKey:@"journal_mode"];
NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption,
[NSNumber numberWithBool:YES], NSInferMappingModelAutomaticallyOption,
sqliteOptions, NSSQLitePragmasOption,
nil];
NSError *error = nil;
_persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]];
if (![_persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:@"Persistent" URL:persistStoreURL options:options error:&error]) {
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
abort();
}
if (![_persistentStoreCoordinator addPersistentStoreWithType:NSInMemoryStoreType configuration:@"Transient" URL:[NSURL URLWithString:@"memory://store"] options:nil error:&error]) {
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
abort();
}
return _persistentStoreCoordinator;
}