开发者

Unable to make NSURL form string

开发者 https://www.devze.com 2023-04-08 01:32 出处:网络
I\'m trying to read a a file in my project. I first create a string with the path and then turn it into a NSURL, and that\'s where I get into trouble:

I'm trying to read a a file in my project. I first create a string with the path and then turn it into a NSURL, and that's where I get into trouble:

NSString *sndPath = [[NSBundle mainBundle] pathForResource:@"vader" ofType:@"caf"];
NSURL *url = [NSURL URLWithString:sndPath]; //url is nil!

The contents of sndPath is:

/Users/fernando/Library/Applicatio开发者_运维知识库n Support/iPhone Simulator/4.3.2/Applications/4B677E62-A6BB-4436-A3DA-EB83A57917FF/Ex1.app/vader.caf

The file does exist, BTW.


When creating a URL that represents a file system path, you should use

+[NSURL fileURLWithPath:]

or

+[NSURL fileURLWithPath:isDirectory:]
0

精彩评论

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