Reputation: 6143
I have added new attribute and I need to migrate core data. As a result, I do like this.
Bus.xcDataModel >> Add model version
Then, I add new attribute. I change persistent store coordinator option as well like this.
@{NSMigratePersistentStoresAutomaticallyOption:@YES, NSInferMappingModelAutomaticallyOption:@YES}
But when I add that new attribute, it show me like this. How shall I do?
-[BusService setBus_wap:]: unrecognized selector sent to instance 0x1742a7320
- (NSPersistentStoreCoordinator *)persistentStoreCoordinator_busservice
{
if (_persistentStoreCoordinator_busservice != nil)
return _persistentStoreCoordinator_busservice;
NSURL *applicationDocumentsDirectory = [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject];
NSURL *storeURL = [applicationDocumentsDirectory URLByAppendingPathComponent:@"Busservice_new.sqlite"];
if (![[NSFileManager defaultManager] fileExistsAtPath:[storeURL path]] &&
!self.preloadEnabled)
{
NSURL *preloadURL = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"Busservice_new" ofType:@"sqlite"]];
NSError* err = nil;
if (![[NSFileManager defaultManager] copyItemAtURL:preloadURL toURL:storeURL error:&err])
DLog(@"Oops, could not copy preloaded data");
}
NSError *error = nil;
_persistentStoreCoordinator_busservice = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]];
if (![_persistentStoreCoordinator_busservice addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:@{NSMigratePersistentStoresAutomaticallyOption:@YES, NSInferMappingModelAutomaticallyOption:@YES} error:&error])
{
DLog(@"Unresolved error %@, %@", error, [error userInfo]);
abort();
}
return _persistentStoreCoordinator_busservice;
}
Upvotes: 1
Views: 80
Reputation: 70976
From that error it looks like you added a new attribute to your BusService
entity in Core Data, but did not add the attribute to your BusService
class. If you want to use accessor methods for this new attribute, you need to update the class as well. Or you can leave the class alone but use setValue:forKey:
to assign values to the new attribute.
Upvotes: 1