How to detect if it is a Web URL or a path?

Discussion in 'Mac Programming' started by saleh.hi.62, Jan 4, 2012.

  1. macrumors member

    Jul 25, 2011
    How to detect if it is a Web URL or a path?

    in NSUrl Apple reference page has written, it accept a URL if it is based on standard, but any kind of string it accept as a URL, like this code:

    NSURL *url=[NSURL URLWithString:@"/book.xml"];
    This is not a web URL but it hold it and also return it as its value.

    My concern is detecting URLs among other paths!
  2. Moderator emeritus


    Jun 15, 2000
    You could check the URL's scheme and if it's http or https it's not a file path. Or use -[NSURL isFileURL] and -[NSFileManager fileExistsAtPath:]
  3. macrumors G5


    Nov 25, 2005
    You are doing it again. You are asking stupid questions - stupid because you leave out what you are actually trying to achieve. Apart from that, the documentation of NSURL, if you could be bothered to read it, tells you exactly what method to use.

Share This Page