Search code examples
iosxcodecore-datansbundle

Fore xcode to load bundle


The core data models are in a bundle which is added to main project. now i have to migrate core data to newer model. i have been following some example like this so i want to migrate database before any queries or import happen. so i placed the code in - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions but the bundle which contains core data models is not loaded at that time. getting hold of bundle says its not yet loaded. So I can't start the migration process.

how can i force it to load this bundle?

is it a good way to have the core data models in a separate bundle other then the main bundle?

edit:

- (NSManagedObjectModel*)objectModel
{
if (_objectModel)
    return _objectModel;

    NSString *bundlePath = [[NSBundle mainBundle] pathForResource:kDataManagerBundleName ofType:@"bundle"];
    NSBundle *bundle = [NSBundle bundleWithPath:bundlePath];

NSString *modelPath = [bundle pathForResource:kDataManagerModelName ofType:@"momd"];
_objectModel = [[NSManagedObjectModel alloc] initWithContentsOfURL:[NSURL fileURLWithPath:modelPath]];

return _objectModel;
}

for the migration part it says bundle not yet loaded and returns nil for pathForResource.


Solution

  • I ended up with moving the data model in main bundle as there is no way to load resources bundle on launching.