Created
April 7, 2015 19:53
-
-
Save Donohue/b7d17e93c6fccf6fb0f6 to your computer and use it in GitHub Desktop.
URL from text
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (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