Skip to content

Instantly share code, notes, and snippets.

@tjeerdintveen
Created February 2, 2017 14:00
Show Gist options
  • Save tjeerdintveen/4293a91f1f680eec186ead24f58c00eb to your computer and use it in GitHub Desktop.
Save tjeerdintveen/4293a91f1f680eec186ead24f58c00eb to your computer and use it in GitHub Desktop.
import UIKit
extension UIView: Showable {
}
protocol Showable {
func layout()
func animate() // Remove me to see the change
}
extension Showable where Self: UIView {
func layout() {
print("layout called from VIEW")
animate()
}
func animate() {
print("animate called from VIEW")
}
}
extension Showable where Self: UIButton {
func layout() {
print("layout called from BUTTON")
animate()
}
func animate() {
print("animate called from BUTTON")
}
}
let view = UIView()
view.layout()
let btn = UIButton()
btn.layout() // This one changes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment