Skip to content

Instantly share code, notes, and snippets.

@4brunu
Last active January 11, 2017 14:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 4brunu/042b8701306644cb26050a49651c28c2 to your computer and use it in GitHub Desktop.
Save 4brunu/042b8701306644cb26050a49651c28c2 to your computer and use it in GitHub Desktop.
Swift - Protocol extensions
//https://speakerdeck.com/realm/natasha-murashev-practical-protocol-oriented-programming?slide=19
import UIKit
protocol Shakeable {
}
extension Shakeable where Self: UIView {
func shake() {
print("shake")
}
}
protocol Jumpable {
}
extension Jumpable where Self: UIView {
func jump() {
print("jump")
}
}
class CustomView: UIView, Shakeable, Jumpable {
}
let customView = CustomView()
customView.shake()
customView.jump()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment