Unable to make NSURL form string
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:]
精彩评论