Override in extension swift - Cannot or Should Not?

272 Views Asked by At

Below is my code snippet?

extension UISwitch{
    open override func draw(_ rect: CGRect) {
        self.tintColor = UIColor.red
    }
}

As per apple documentation, you should not override in extension. I understand this. Now I am not getting an error in this code and all switches in my application are having red as tint color.

I have read articles that this is working because of dynamic dispatch as UISwitch is class in inherited by NSObject.

Can someone help me understand this concept? Why should we not do this? If swift is static dispatch how does this still work?

0

There are 0 best solutions below