code will increase…. eventually leading to massive view controller issue - Some people prefer to have all their state management code in BaseViewController (A controller which all the other view controller implements)
not re-usable. Leads to code duplication & bad design. - Are you following DRY pattern? - Will code refactoring be easier following this kind of architecture?
protocols 2. Re-usable code 3. Protocols can be implemented by a class, struct or enum. Protocols can have default implementations for requirements specified in a protocol extension allowing `mixin` or `trait` like patterns.
manage the addition/removal of views. It has access to the current view state being displayed on the screen. 1. viewstore variable -> to store the views on the basis of the state type 2. getView method -> Returns the view for a given state 3. addView method -> Associates/adds a view for the given state 4. removeView method -> Removes a view for the given state 5. removeAllViews method -> Remove all views and empty the viewstore property
be implemented by any View Controller class to add/remove view for a given state. It has some abstract methods and properties. The extension of ViewStateProtocol has the default implementation of those abstract methods and properties.
Any view controller class can implement this protocol to add/remove views without writing any extra line of code. Multiple Inheritance Protocol extension allows us to retain one of the best features of subclassing(inheritance). Using protocols allows us to inherit from multiple parents simultaneously Not Limited to classes Protocols can be adopted by classes, enums or structs whereas base classes and inheritance are available for classes only. Conditional Extensions By using where keyword, we only extend protocol for types that inherit from UIViewController, we are able to use UIViewController specific methods.
of state management involved - The biggest challenge comes in re-using the code but most tutorials tend to ignore them - Proper architecture to manage states in any networked application. - Protocol extensions is a powerful feature that needs to be explored more.