Created
December 7, 2017 14:24
-
-
Save BjornRuud/0966bacaa5eca49ae6c45a3373a009dc to your computer and use it in GitHub Desktop.
URL namespace to collect URLs in a convenient place.
This file contains 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
extension URL { | |
enum MyURLNamespace { | |
// Static URL, always in memory | |
static let gitHub = URL(string: "https://github.com/BjornRuud")! | |
// Computed URL, created on demand | |
static var gitHubWithStaticParameter: URL { | |
let param = "SomeParameter" | |
return URL(string: "https://github.com/BjornRuud/\(param)")! | |
} | |
// Computed URL with parameters | |
static func gitHubHome(userID: String) -> URL { | |
return URL(string: "https://github.com/\(userID)")! | |
} | |
} | |
static let mynamespace = MyURLNamespace.self | |
} | |
// Usage: | |
let url = URL.mynamespace.gitHub |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment