Last active
January 19, 2021 19:42
-
-
Save ULazdins/3d5842f9d1a587f6b7af9ffbbc91efc3 to your computer and use it in GitHub Desktop.
Things In Code: URL parameter concatenation2
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
- (NSString *)prepareUrl { | |
NSMutableArray *queryComponents = [NSMutableArray new]; | |
if (query != nil) { | |
[queryComponents addObject:[NSString stringWithFormat:@"query=%@", query]]; | |
} | |
if (orderBy != nil) { | |
[queryComponents addObject:[NSString stringWithFormat:@"orderBy=%@", orderBy]]; | |
} | |
if (sortOrder != nil) { | |
[queryComponents addObject:[NSString stringWithFormat:@"sortOrder=%@", sortOrder]]; | |
} | |
// .. and so on | |
NSString *parameters = [queryComponents componentsJoinedByString:@"&"]; | |
return [NSString stringWithFormat:@"https://example.com?%@", parameters]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment