Skip to content

Instantly share code, notes, and snippets.

@Donohue
Created April 7, 2015 19:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Donohue/b7d17e93c6fccf6fb0f6 to your computer and use it in GitHub Desktop.
Save Donohue/b7d17e93c6fccf6fb0f6 to your computer and use it in GitHub Desktop.
URL from text
- (NSURL *)URLFromText:(NSString *)text {
NSArray *components = [text componentsSeparatedByCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
NSURL *ret = nil;
for (NSString *part in components) {
NSURL *urlCheck = [NSURL URLWithString:part];
if (urlCheck &&
([urlCheck.scheme isEqualToString:@"http"] ||
[urlCheck.scheme isEqualToString:@"https"])) {
ret = urlCheck;
break;
}
}
return ret;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment