views:

2109

answers:

1

I'm working through Cocoa smoothly, but this problem seems so basic it cancels out all the cool stuff I learned. :/

I have a generated file path, and it needs to be in NSURL format. From research, this is the code I wrote:

NSLog(@"Old path = %@", pathToFile);
NSURL *xmlURL = [[[NSURL alloc] init] fileURLWithPath:pathToFile];
NSLog(@"New path = %@", [xmlURL absoluteString]);

And the output:

2010-01-27 15:39:22.105 MusicLibraryStats[28574:a0f] Old path = file://localhost/Users/[username]/Music/iTunes/iTunes%20Music%20Library.xml
2010-01-27 15:39:22.105 MusicLibraryStats[28574:a0f] New path = (null)

First off, the alloc-init shouldn't even be necessary; other people seem to get away with it. In this case, if I don't alloc-init, I get an 'unrecognized selector' error on that line. Of course, now I'm just getting plain old (null).

Where did I goof?

Thanks!

+5  A: 
zneak
I see. Thanks. What method is available (if any) to turn the string I have now into what you have?Breakpoints are indeed useful, but there's not much that I can do with them in this situation. I can step into fileURLWithPath: , but if a runtime error is involved (like when I didn't alloc-init), the best I can do is examine the assembly.
spamguy
All you need to do this this: `NSURL *xmlURL = [NSURL fileURLWithPath:pathToFile];` If you still have problems, the issue might be with `pathToFile`. Use the debugger to find out.
Alex
Nope, the string is most definitely plain ol' file://localhost/Users/[username]/Music/iTunes/iTunes%20Music%20Library.xml . It was generated using NSOpenPanel...pathToFile = [[oPanel URLs] objectAtIndex:0];
spamguy