views:

181

answers:

1

Just trying to get into the Core Data stuff and getting crossed up right off the bat. In my AppDelegate I have the following code:

- (NSManagedObjectModel *)managedObjectModel {

    if (managedObjectModel_ != nil) {
        return managedObjectModel_;
    }
    NSString *modelPath = [[NSBundle mainBundle] pathForResource:@"DataModel" ofType:@"momd"];
    NSURL *modelURL = [NSURL fileURLWithPath:modelPath];
    managedObjectModel_ = [[NSManagedObjectModel alloc] initWithContentsOfURL:modelURL];    
    return managedObjectModel_;
}

Where @"DataModel" is the name of my .xcdatamodel file - is this correct?

A: 

It is often easier to change this to

managedObjectModel_ = [[ManagedObjectModel mergedModelFromBundle:nil] retain];

Then if it is a mom or momd you will still get the model back.

Marcus S. Zarra