Extension in Swift
Contents
Swift allows us to define more methods on existing class using extension.
1 |
extension UIView { |
If you ‘re afraid of the naming conflict, you can prefix your methods. Or a better way, reverse it :dancer: , like
1 |
view.animation.shake() |
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
1 |
extension UIView { |
This is applied in Wave