Creating ImageStore
In Chapter 13, you had Items write out their properties to a file, and those properties are then read in when the application starts. However, because images tend to be very large, it is a good idea to keep them separate from other data.
You are going to store the pictures the user takes in an instance of a class named ImageStore. The image store will fetch and cache the images as they are needed. It will also be able to flush the cache if the device runs low on memory.
Create a new Swift file named ImageStore. In ImageStore.swift, define the ImageStore class and add a property that is an instance of NSCache.
Listing 15.9 Adding the ImageStore class (ImageStore.swift)
import Foundationimport UIKit ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access