Issue #11
Swift allows us to define more methods on existing class using extension.
extension UIView {
func shake() {
}
func fade() {
}
func centerIn(anotherView: UIView) {
}
}
If you ‘re afraid of the naming conflict, you can prefix your methods, like
view.abc_shake()
view.abc_fade()
view.abc_centerIn(anotherView: containerView)
Or a better way, reverse it 💃 , like
view.animation.shake()
view.animation.fade()
view.layout.centerIn(anotherView)
This way, no more conflict and we make it clear that shake()
and fade()
belongs to animation category
Actually, animation and layout are properties in UIView extension. This may cause naming conflict, but the number of them is reduced
This is how it works
extension UIView {
struct Animation {
let view: UIView
func shake() {
// Shake the view
}
func fade() {
PowerfulAnimationEngine.fade(view)
}
}
var animation: Animation {
return Animation(view: self)
}
struct Layout {
let view: UIView
func centerIn(anotherView: UIView) {
}
}
var layout: Layout {
return Layout(view: self)
}
}