April 2020
Beginner
316 pages
8h 20m
English
First off, we'll need to make some tweaks to our RecipeModel(). Head on over to the RecipeModel.swift file and make the following highlighted changes:
var ingredients = [String]()var recipe = ""var imageData: Data?var image: UIImage { if let dataImage = UIImage(data: imageData ?? Data()) { return dataImage } else if let countryImage = UIImage(named: countryCode) { return countryImage } return UIImage()}
Here, we've added one property called imageData and a computed property called image.
The imageData property will be home to the converted UIImage that we previously selected. Converting the image to Data() will allow this to be successfully persisted to UserDefaults.
Our computed property doesn't hold value as such; ...
Read now
Unlock full access