I have a datamodel file "Abcde.xcdatamodeld" . It is currently a part of my main bundle and I am referencing it by using the following code.
- (NSManagedObjectModel *)managedObjectModel {
if (managedObjectModel_ != nil) {
return managedObjectModel_;
}
NSString *modelPath = [[NSBundle mainBundle] pathForResource:@"Abcde" ofType:@"momd"];
NSURL *modelURL = [NSURL fileURLWithPath:modelPath];
managedObjectModel_ = [[NSManagedObjectModel alloc] initWithContentsOfURL:modelURL];
return managedObjectModel_;
}
Now I have a requirement where in the "Abcde.xcdatamodeld" should be made to be a part of a diffrent bundle and it should be referenced from the new bundle. `
if (managedObjectModel_ != nil) {
return managedObjectModel_;
}
NSBundle *dataModelBundle = [NSBundle bundleWithIdentifier:@"com.product.dataModelBundle"];
NSString *modelPath = [dataModelBundle pathForResource:@"Abcde" ofType:@"momd"];
NSURL *modelURL = [NSURL fileURLWithPath:modelPath];
managedObjectModel_ = [[NSManagedObjectModel alloc] initWithContentsOfURL:modelURL];
return managedObjectModel_;
}
But I am experiencing a crash while running the above code.. MY questions are;
- Can a datamodel class be part of any other bundle than the main bundle.
- If yes, then where am I going wrong here.