NSURL *modelURL1 = [[NSBundle mainBundle] URLForResource:@"MyTest" withExtension:@"momd"];
NSLog(@"%@", [modelURL1 absoluteURL]);
NSString *path = [[NSBundle mainBundle] pathForResource:@"MyTest" ofT开发者_StackOverflow社区ype:@"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
The second one doesn't work because path isn't a URL. Use this instead:
NSURL *modelURL = [NSURL fileURLWithPath:path];
精彩评论