开发者

NSBundle pathForResource method

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];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜