PDA

View Full Version : How to detect if it is a Web URL or a path?




saleh.hi.62
Jan 5, 2012, 01:01 AM
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"];

NSLog(@"%@",url);

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!



kainjow
Jan 5, 2012, 09:55 PM
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:]

gnasher729
Jan 6, 2012, 11:35 AM
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"];

NSLog(@"%@",url);

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!

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.