I have Core Data model and it work fine, but I need to add new attribute. I click on my .xcdatamodel and go to Editor/Add Model Version. Now I add new attribute and add this in .h and .m file.
When I run application it give me an error :
[CubeCategory setStoreDescription:]: unrecognized selector sent to instance 0x1657bca0
Now, even if I delete application from device and instal from fresh it still give me same error.
What I am doing wrong?
EDIT :
I have set my new model as current model :
My model looks like :
And Class looks like :
.h :
@interface CubeCategory : NSManagedObject
@property (nonatomic, retain) NSNumber * categoryID;
@property (nonatomic, retain) NSNumber * position;
@property (nonatomic, retain) NSString * title;
@property (nonatomic, retain) NSNumber * type;
@property (nonatomic, retain) NSString * storeDescription;
@property (nonatomic, retain) NSNumber * lock;
@property (nonatomic, retain) NSSet *cube;
@property (nonatomic, retain) Server *server;
@end
@interface CubeCategory (CoreDataGeneratedAccessors)
- (void)addCubeObject:(Cube *)value;
- (void)removeCubeObject:(Cube *)value;
- (void)addCube:(NSSet *)values;
- (void)removeCube:(NSSet *)values;
-(id)init:(NSManagedObjectContext*)Context;
-(void)save:(NSManagedObjectContext*)Context;
@end
and .m
@implementation CubeCategory
@dynamic categoryID;
@dynamic position;
@dynamic title;
@dynamic type;
@dynamic cube;
@dynamic server;
@dynamic lock;
@dynamic storeDescription;
-(id)init:(NSManagedObjectContext*)Context{
self = [NSEntityDescription insertNewObjectForEntityForName:@"CubeCategory" inManagedObjectContext:Context];
return self;
}
-(void)save:(NSManagedObjectContext*)Context{
NSError *error;
if (![Context save:&error]) {
NSLog(@"Whoops, couldn't save: %@", [error localizedDescription]);
}
}
@end
In my AppDelegate I have set :
- (NSPersistentStoreCoordinator *)persistentStoreCoordinator
{
NSDictionary *options = @{
NSMigratePersistentStoresAutomaticallyOption : @YES,
NSInferMappingModelAutomaticallyOption : @YES
};
...
if (![__persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:options error:&error]) {
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
}
EDIT 2:
- (NSManagedObjectModel *)managedObjectModel
{
if (__managedObjectModel != nil) {
return __managedObjectModel;
}
NSURL *modelURL = [[NSBundle mainBundle] URLForResource:@"Model" withExtension:@"mom"];
__managedObjectModel = [[NSManagedObjectModel alloc] initWithContentsOfURL:modelURL];
return __managedObjectModel;
}
// 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
{
NSDictionary *options = @{
NSMigratePersistentStoresAutomaticallyOption : @YES,
NSInferMappingModelAutomaticallyOption : @YES
};
if (__persistentStoreCoordinator != nil) {
return __persistentStoreCoordinator;
}
NSURL *storeURL = [[self applicationDocumentsDirectory] URLByAppendingPathComponent:@"BiViewNew.sqlite"];
NSError *error = nil;
__persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]];
if (![__persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:options error:&error]) {
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
}
return __persistentStoreCoordinator;
}