I saw this question, with this code:
protocol Flashable {}
extension Flashable where Self: UIView
{
func flash() {
UIView.animate(withDuration: 0.3, delay: 0, options: .curveEaseIn, animations: {
self.alpha = 1.0 //Object fades in
}) { (animationComplete) in
if animationComplete == true {
UIView.animate(withDuration: 0.3, delay: 2.0, options: .curveEaseOut, animations: {
self.alpha = 0.0 //Object fades out
}, completion: nil)
}
}
}
}
And I wonder why do we you not just directly just extend UIView
? Or in similar cases extend UIViewController
why twist it around with a where Self:
- Is it so that we increase our intent and when other developers come they would see that hey this class is conforming to Flashable, Dimmable, etc?
- Also our UIView would have separate meaningful extensions? Instead of different unNamed extensions to UIView or UIViewController?
- Are there any specific Apple guidelines on this subject for POP? I've seen there developer doing it this way but not sure of the why...