Last active
October 12, 2020 05:06
-
-
Save ha1f/2f5873372153f9cda67fa344a2718a50 to your computer and use it in GitHub Desktop.
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
/// JavaのStringBuilder的なインターフェースを想定 | |
final class URLBuilder { | |
private var components: URLComponents | |
init?(string: String) { | |
guard let components = URLComponents(string: string) else { | |
return nil | |
} | |
self.components = components | |
} | |
@discardableResult | |
func append(_ queryItem: URLQueryItem) -> URLBuilder { | |
var newItems = components.queryItems ?? [] | |
newItems.append(queryItem) | |
components.queryItems = newItems | |
return self | |
} | |
func build() -> URL? { | |
components.url | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment