Last active
March 4, 2016 09:25
-
-
Save sinsoku/dcfe5e1291c3a6351dbb to your computer and use it in GitHub Desktop.
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
class User {} | |
protocol Twitter { | |
// var username: String { get } | |
} | |
extension Twitter { | |
var username: String { | |
get { return "tryswiftconf" } | |
} | |
} | |
func showTwitter(user: Twitter) { | |
print(user.username) | |
} | |
extension User: Twitter {} | |
// GitHub | |
protocol GitHub { | |
// var username: String { get } | |
} | |
extension GitHub { | |
var username: String { | |
get { return "lattner" } | |
} | |
} | |
func showGitHub(user: GitHub) { | |
print(user.username) | |
} | |
extension User: GitHub {} | |
let user = User() | |
showTwitter(user) // tryswiftconf | |
showGitHub(user) // lattner |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment