Skip to content

Instantly share code, notes, and snippets.

@AlexChesters
Last active December 8, 2015 14:32
Show Gist options
  • Save AlexChesters/c554533bf8b85891e119 to your computer and use it in GitHub Desktop.
Save AlexChesters/c554533bf8b85891e119 to your computer and use it in GitHub Desktop.
URLBuilder class written in Objective-C
//
// URLBuilder.h
// lyrical
//
// Created by Alex Chesters on 13/11/2015.
// Copyright © 2015 Alex Chesters. All rights reserved.
//
#import <Foundation/Foundation.h>
@interface URLBuilder : NSObject
- (NSURL *)withScheme:(NSString *)scheme host:(NSString *)host path:(NSString *)path queryItems:(NSArray *)queryItems;
@end
//
// URLBuilder.m
// lyrical
//
// Created by Alex Chesters on 13/11/2015.
// Copyright © 2015 Alex Chesters. All rights reserved.
//
#import "URLBuilder.h"
@implementation URLBuilder
- (NSURL *)withScheme:(NSString *)scheme host:(NSString *)host path:(NSString *)path queryItems:(NSArray *)queryItems {
NSURLComponents *components = [[NSURLComponents alloc] init];
[components setScheme:scheme];
[components setHost:host];
[components setPath:path];
if (queryItems && queryItems.count > 0) {
[components setQueryItems:queryItems];
}
return components.URL;
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment