开发者

NSBundle pathForResource method

开发者 https://www.devze.com 2023-02-23 17:58 出处:网络
NSURL *modelURL1 = [[NSBundle mainBundle] URLForResource:@\"MyTest\" withExtension:@\"momd\"]; NSLog(@\"%@\", [modelURL1 absoluteURL]);
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

精彩评论

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