Darren
Darren

Reputation: 10129

NSBundle instance method URLForResource:withExtension returning invalid CFStringRef on device

I make the following method call in my code:

NSURL *modelURL = [[NSBundle mainBundle] URLForResource:@"myappname" withExtension:@"momd"];

When I run on the simulator, this returns an NSURL that works. When I run on my device, it returns an invalid CFStringRef. What am I doing wrong?

Another related question, my xcode project file is named like this: "MyApp", and the end of my bundle identifier is named like this: "myapp".

I have tried both ways and I get the same result, but I've read that the resource parameter string is case sensitive. Which one am I supposed to use?

Upvotes: 0

Views: 1454

Answers (1)

graver
graver

Reputation: 15213

Try:

NSString *modelPath = [[NSBundle mainBundle] pathForResource:@"YourModelName" ofType:@"momd"];
NSManagedObjectModel *objectModel = [[NSManagedObjectModel alloc] initWithContentsOfURL:[NSURL fileURLWithPath:modelPath]];

Upvotes: 1

Related Questions