Explores why view models remain essential in SwiftUI applications despite common arguments against them. Demonstrates how MVVM pattern improves testability, maintainability, and code reuse by separating business logic from views. Addresses misconceptions about Apple's stance on view models and shows how they work with

27m read timeFrom matteomanferdini.com
Post cover image
Table of contents
FREE GUIDE - SwiftUI App Architecture: Design Patterns and Best PracticesTable of contentsThe Software Design Principles behind MVVMMonolithic SwiftUI views are hard to maintain and unit testShould you use view models in SwiftUI, or is the MVVM pattern outdated?View State Transitions and Imperative LogicFREE GUIDE - SwiftUI App Architecture: Design Patterns and Best PracticesThe state transitions of a view are driven by imperative code, despite SwiftUI’s declarative natureThe imperative logic of a SwiftUI view is untestable because of the framework’s internal implementationA view’s state transitions are a crucial part of the app’s business logicAggregate models should not contain view-specific logic, as they are shared across several viewsImplementing and Testing View ModelsFREE GUIDE - SwiftUI App Architecture: Design Patterns and Best PracticesImplementing view models as observable objectsYou still need unit tests even when you use UI testsView models should be instantiated inside a viewHow MVVM Interacts with Apple FrameworksFREE GUIDE - SwiftUI App Architecture: Design Patterns and Best PracticesIs Apple actively against MVVM, or do they endorse it?Is MVVM incompatible with SwiftData and other Apple frameworks?The MVC and MVVM Desing Patterns in SwiftUIFREE GUIDE - SwiftUI App Architecture: Design Patterns and Best PracticesApple used to explicitly endorse a variation of MVC equivalent to MVVM, which was baked into UIKitThe MV pattern is an anti-pattern because it’s too prescriptiveA design pattern for real-world SwiftUI applicationsConclusionsSwiftUI App Architecture: Design Patterns and Best Practices

Sort: