LuckyLuke
LuckyLuke

Reputation: 49077

NSBundle pathForResource method

NSURL *modelURL1 = [[NSBundle mainBundle] URLForResource:@"MyTest" withExtension:@"momd"];
NSLog(@"%@", [modelURL1 absoluteURL]);

NSString *path = [[NSBundle mainBundle] pathForResource:@"MyTest" ofType:@"momd"];
NSURL *modelURL = [NSURL URLWithString:path];
NSLog(@"%@", [modelURL absoluteURL]);

The first line is generated by XCode when I use Core Data, but it does not work because the method doesn't work prior to iOS 4. So I need another method, I thought I could use the second one but it returns nil...Why does it not work?

Thanks

Upvotes: 1

Views: 1037

Answers (1)

Sherm Pendley
Sherm Pendley

Reputation: 13612

The second one doesn't work because path isn't a URL. Use this instead:

NSURL *modelURL = [NSURL fileURLWithPath:path];

Upvotes: 2

Related Questions