Swift: Invoking Caller's Method with Protocols

One line problem/solution: using [Protocols](swift protocol optional) when delegating calls to the caller class from a Factory. I have a Button Factory (ButtonFactory.swift) which gives the user an instance of UIButton in a simple grid view (GridView.swift), which will invoke a method on the main class that calls the factory. A quick & simple solution to this would be like: - ButtonFactory.swift protocol ButtonDelegate { func buttonPressed(button:UIButton) } class ButtonFactory { var delegate:ButtonDelegate! func create(...) -> UIButton { let button = CustomButton() button.addTarget(self, action:…

Keep reading