I have identical methods in different view controller classes which basically it adds a blur effect to the view controllers. Now I'm trying to use other swift types to simplify my code but am confused how to implement this so that adding subviews work properly. What's a good methodology to approach such cases ? Extension , protocol, struct, class or other func?
Here's a view controller (simplified here) :
import UIKit
class MyClass: UIViewController {
weak var blurEffectView : UIVisualEffectView?
.... other methods ....
func addBlurrEffect() {
let blurEffect = UIBlurEffect(style: UIBlurEffectStyle.dark)
let blurEffectVw = UIVisualEffectView(effect: blurEffect)
blurEffectVw.frame = self.view.bounds
blurEffectVw.autoresizingMask = [.flexibleWidth, .flexibleHeight] // for supporting device rotation
self.view.addSubview(blurEffectVw)
blurEffectView = blurEffectVw
}
... other methods ....
}
I have other similar view controller. How can I refactor them to only use addBlurEffect() once in the entire project?