Skip to content

Instantly share code, notes, and snippets.

@sinsoku
Created January 16, 2016 15:24
Show Gist options
  • Save sinsoku/001b99f6c182aa3c4bb5 to your computer and use it in GitHub Desktop.
Save sinsoku/001b99f6c182aa3c4bb5 to your computer and use it in GitHub Desktop.
protocol による多重継承
protocol ExternalAccount {}
extension ExternalAccount {
func save() {
print("PATCH http://api.external.com/user")
}
}
protocol DataBaseAccount {}
extension DataBaseAccount {
func save() {
print("Save to Database")
}
}
class User: DataBaseAccount, ExternalAccount {}
func updateProfile(user:ExternalAccount) {
user.save()
}
let user = User()
updateProfile(user)
//=> PATCH http://api.external.com/user
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment