struct Developer: CustomStringConvertible {
enum Language: String {
case c, objC, swift
}
let platform: String
let language: Language
let username: String
private var gitHubURL: URL? {
URL(string: "https://github.com/\(username)")
}
var description: String {
let desc = "\(platform). \(language.rawValue.capitalized)."
guard let gitHubURL = gitHubURL else {
return desc
}
return [desc, String(describing: gitHubURL)].joined(separator: "\n")
}
func openGitHub() {
guard let url = gitHubURL else { return }
UIApplication.shared.open(url)
}
}
// iOS. Swift.
// https://github.com/kfweber
let dev = Developer(platform: "iOS", language: .swift, username: "kfweber")
print(dev)