PDA

View Full Version : Convert path to NSURL




satyam90
Nov 26, 2007, 07:20 AM
I am using
NSURL *url = [[NSURL alloc] URLWithString:[[NSBundle mainBundle] bundlePath]];
to convert the path to NSURL.
But url is null after the statement of execution. Can anyone tell me how to do this?



robbieduncan
Nov 26, 2007, 07:31 AM
I would use


NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] bundlePath]];


Note the url returned will be autoreleased: you might want to retain it...

kainjow
Nov 26, 2007, 11:22 AM
I am using
NSURL *url = [[NSURL alloc] URLWithString:[[NSBundle mainBundle] bundlePath]];
to convert the path to NSURL.
But url is null after the statement of execution. Can anyone tell me how to do this?

URLWithString: takes a string representation of a URL. bundlePath returns a path, not a URL, that is why you have to use fileURLWithPath.