-
Book Overview & Buying
-
Table Of Contents
-
Feedback & Rating

Learning Swift Second Edition
By :

We have already made some good progress on the core functionality of our app. However, before we move any further, we should reflect on the code we have written. Ultimately, we haven't actually written that many lines of code, but it can definitely be improved. The biggest shortcoming of our code is that we have put a lot of business logic inside our view controller. This is not a good separation of our different model, view, and controller layers. Let's take this opportunity to refactor this code into a separate type.
We will create a class called PhotoStore
that will be responsible for storing our photos and that will implement the data source protocol. This will mean moving some of our code out of our view controller.
First, we will move the photo's property to the photo store class:
import UIKit class PhotoStore: NSObject { var photos = [Photo]() }
Note that this new photo store class inherits from NSObject
. This is necessary for us to be...
Change the font size
Change margin width
Change background colour