December 2018
Intermediate to advanced
414 pages
10h 19m
English
The factory method pattern is particularly suited to configuring the objects provided by SDKs in a reliable manner. For example, we may want to have a common way to instantiate alerts for our users when there's an error in the app.
Let's see how we can apply this with the popular iOS view controller UIAlertController. This controller is used to display a message to the user, either in the form of an alert or an action sheet.
In object-oriented languages, we'd create a factory object, and issue the objects from a factory, as follows:
class UIAlertControllerFactory { static let sharedFactory = UIAlertControllerFactory() private init() {} func alertControllerFor(error: Error, onOK handler: @escaping ...
Read now
Unlock full access