Convert path to NSURL

Discussion in 'Mac Programming' started by satyam90, Nov 26, 2007.

  1. macrumors regular

    satyam90

    Joined:
    Jul 30, 2007
    Location:
    Bangalore, India
    #1
    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?
     
  2. Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #2
    I would use

    Code:
    NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] bundlePath]];
    
    Note the url returned will be autoreleased: you might want to retain it...
     
  3. Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #3
    URLWithString: takes a string representation of a URL. bundlePath returns a path, not a URL, that is why you have to use fileURLWithPath.
     

Share This Page