Can a iphone/ipad universal app have two different xcdatamodel files?
I dont want to go through the d开发者_如何转开发ata migration with an existing iphone app. Is is possible to have the ipad version use a different xcdatamodel file than the iphone version?
I search the project files where it reference myapp.xcdatamodel and cant find where it gets hooked up.
any suggestions?
Where is the appdelegate does it set this?
i do see:
NSURL *storeUrl = [NSURL fileURLWithPath: [[self applicationDocumentsDirectory] stringByAppendingPathComponent: @"storeLocations.sqlite"]];
There's nothing magical about the persistent store coordinator or any other part of core data. They're just objects with methods and properties, like anything else.
In your app delegate you just need to specify more than one, a la:
header
NSManagedObjectContext *managedObjectContext;
NSManagedObjectModel *managedObjectModel;
NSPersistentStoreCoordinator *persistentStoreCoordinator;
NSManagedObjectContext *managedObjectContext2;
NSManagedObjectModel *managedObjectModel2;
NSPersistentStoreCoordinator *persistentStoreCoordinator2;
implementation
- (NSManagedObjectContext *)managedObjectContext {
if (managedObjectContext != nil) {
return managedObjectContext;
}
NSPersistentStoreCoordinator *coordinator = [self persistentStoreCoordinator];
if (coordinator != nil) {
managedObjectContext = [[NSManagedObjectContext alloc] init];
[managedObjectContext setPersistentStoreCoordinator:coordinator];
}
return managedObjectContext;
}
and
- (NSManagedObjectContext *)managedObjectContext2 {
if (managedObjectContext2 != nil) {
return managedObjectContext2;
}
NSPersistentStoreCoordinator *coordinator2 = [self persistentStoreCoordinator2];
if (coordinator2 != nil) {
managedObjectContext2 = [[NSManagedObjectContext alloc] init];
[managedObjectContext2 setPersistentStoreCoordinator:coordinator2];
}
return managedObjectContext2;
}
etc.
The model gets hooked up in your App Delegate.
NSString *modelPath = [[NSBundle mainBundle] pathForResource:@"myApp"
ofType:@"momd"];
I would suggest against two models, but I also have no idea how it would really work. I am guessing conditionals around the object model and persistent store.
How different is your ipad model that you would need another model but not a different app?
I remember reading stuff in the core data doco about specifying which persistant store a managed objext is stored. See NsManagedObjectContext assignObject:toPersistentStore:
. That will lead you in the right direction I think. You will probably need to instantiate multiple persistant store objects.
精彩评论