Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSManagedObjectModel initWithContentsOfURL returns nil eventhough the modelURL is valid

Tags:

my NSManagedObjectModel is returning nil eventhough the path is correct.

        NSString *modelKey = [NSString stringWithFormat:@"/%@/Model", name];
    NSString *modelPath = [((Configuration *)[Configuration shared]) stringEntry:modelKey];
    NSURL *modelURL = nil;
    if ( ! [modelPath contains:@"://"] ) {
        modelPath = PathForBundleResource( modelPath );
        modelURL = [NSURL fileURLWithPath:modelPath];
    }
    NSManagedObjectModel *m = [[NSManagedObjectModel alloc] initWithContentsOfURL:modelURL];

NSString *PathForBundleResource(NSString *relativePath)

    NSString* resourcePath = [[NSBundle mainBundle] resourcePath];
return [resourcePath stringByAppendingPathComponent:relativePath];

I've reset the simulator, did a clean build but nothing helped.

I'm new to iPhone programming (core data in particular).

Would appreciate any help.

Edit: I've edited the original post regarding the xcdatamodeld file. It wasn't linked up properly initially but now it is and still having the same problem.

Edit 2: Apparently the name of the xcdatamodel had some variations to the name of the xcdatamodel after linkage. It's working now. Feeling so stupid. Don't know how to delete this question.

like image 355
newDeveloper Avatar asked Jul 19 '11 15:07

newDeveloper


1 Answers

I had the same problem after I renamed .xcdatamodeld file. The problem was solved by closing and reopening the Xcode client.

like image 121
IPhone Guy Avatar answered Sep 30 '22 20:09

IPhone Guy