I saw this question, with this code:
protocol Flashable {}
extension Flashable where Self: UIView
{
func flash() {
UIView.animate(withDuration:
This approach is preferable to using UIView directly, as in
extension UIView {
func flash() {
...
}
}
because it lets programmers decide which UIView subclasses they wish to make Flashable, as opposed to adding flash functionality "wholesale" to all UIViews:
// This class has flashing functionality
class MyViewWithFlashing : UIView, Flashable {
...
}
// This class does not have flashing functionality
class MyView : UIView {
...
}
Essentially, this is an "opt in" approach, while the alternative approach forces the functionality without a way to "opt out".