mardi 4 août 2015

Core Data Model Url is Nil in Framework

I am using Apple Documented Code to link up CoreData xcdatamodeld file but it works brilliantly in the project but fails in Framework. Here is the code I am using to create the managedObjectModel. I get nil modelURL in case of Framework.

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentDirectory = [paths lastObject];

    self.persistantStorePath = [documentDirectory stringByAppendingString:[NSString stringWithFormat:@"/%@.sqlite",name]];
    NSURL *storeURL = [NSURL fileURLWithPath:self.persistantStorePath];
    NSURL *modelURL = [[NSBundle mainBundle] URLForResource:name withExtension:@"momd"];

    self.managedObjectContext = [[NSManagedObjectContext alloc] init];
    self.managedObjectModel = [[NSManagedObjectModel alloc] initWithContentsOfURL:modelURL];

Also, I tried [NSManagedObjectModel mergedModelFromBundles:nil] and the surprising point is, it works too.

I don't know why the Apple Documentation fails in case of Framework



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire