Last active
January 11, 2017 14:05
-
-
Save 4brunu/042b8701306644cb26050a49651c28c2 to your computer and use it in GitHub Desktop.
Swift - Protocol extensions
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
//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