From the course: iOS Development: Architecture
Unlock the full course today
Join today to access over 22,700 courses taught by industry experts or purchase this course individually.
Refactoring to MVP: Model
From the course: iOS Development: Architecture
Refactoring to MVP: Model
- [Narrator] Instead of accessing the model directly, we extract it to a dedicated model type. I create a new Swift file called Model. Now, I declare a structure called Model. Let's make it generic so that it can store any type. We need a backend storage. The private objects property is a generic array. Next, we need a method for inserting new elements. The insert method is mutating since it modifies the contents of the struct. The method simply inserts the new element to the beginning of the list. We also have to remove elements from the model, thus I provide the remove at index method. It's also mutating since it modifies the contents of the struct. It is recommended to check whether the index is valid. Calling the arrays Remove At method with an invalid index would crash the app, so I only call Remove At if the index passed its argument can be found within the array's instances. The model should provide the number of its entries. The count read only property returns the number of…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
Introduction to fundamental architectural design patterns57s
-
(Locked)
The model-view-controller3m 50s
-
(Locked)
The model-view-presenter1m 22s
-
(Locked)
MVP example2m 41s
-
(Locked)
Refactoring to MVP: Model2m 26s
-
(Locked)
Refactoring to MVP: Presenter2m 32s
-
(Locked)
Refactoring to MVP: View controller4m 29s
-
(Locked)
The Model-View-ViewModel pattern1m 15s
-
(Locked)
Implementing one-way binding, part 11m 34s
-
(Locked)
Implementing one-way binding, part 23m 55s
-
-
-
-
-
-
-