Created
October 1, 2012 17:02
-
-
Save marcuswestin/3813026 to your computer and use it in GitHub Desktop.
Code to match parts of a url using NSPredicates
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* url = [NSURL URLWithString:@"http://www.google.com/path/to/foo?aParam=value"]; | |
url.absoluteString; | |
url.host; | |
url.scheme; | |
url.path; | |
NSArray* arr = [NSArray arrayWithObjects:url, [NSURL URLWithString:@"https://marcuswest.in/teachers"], nil]; | |
NSLog(@"scheme %@", [arr filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"scheme MATCHES 'http'"]]); | |
NSLog(@"host %@", [arr filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"host MATCHES 'www.google.com'"]]); | |
NSLog(@"host 2 %@", [arr filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"host MATCHES '^www.google.*'"]]); | |
NSLog(@"path %@", [arr filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"path MATCHES '^www.google.*'"]]); | |
NSLog(@"absolute %@", [arr filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"absoluteString MATCHES '^http.*path.*'"]]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment