Skip to content

Instantly share code, notes, and snippets.

@ha1f
Last active Oct 12, 2020
Embed
What would you like to do?
/// 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