I assume that at the URL you are referring to a string identifying the location of the Internet resource.
If you have an idea of ββthe format of the input string, why not manually check if the string starts with http:// , https:// or any other scheme you need. If you expect other protocols, you can also add them to the checklist (e.g. ftp:// , mailto:// , etc.)
if ([myString hasPrefix:@"http://"] || [myString hasPrefix:@"https://"]) { // do something }
If you are looking for a more robust solution and find some kind of URL pattern, you should use a regex.
As an additional note, the NSURL class is intended to express any kind of resource location (and not just Internet resources). This is why lines like img/demo.jpg or file://bla/bla/bla/demo.jpg can be converted to NSURL objects.
However, according to the documentation, [NSURL URLWithString] should return nil if the input string is not a valid Internet resource string. In practice, this is not so.
Andrei Stanescu
source share