I'm making an app that has a collection view of plants. I have Plant class that implements the NSCoding protocol so I can save them. The plants are stored in an array called plantList.
var plantList = [Plant]
And here's what I store in my Plant class:
class Plant: NSObject, NSCoding {
var name: String
var species: String
var nextWateredDate: Date
var wateringPeriod: Int
var wateringCount: Int
var profileImage: UIImage?
Whenever a plant is added to the plantList or a plant is edited, I save the plantList like so:
func savePlants() {
NSKeyedArchiver.archiveRootObject(plantList, toFile:
Plant.ArchiveURL.path)
}
My issue is that when I have more than a few plants in my plantList, then savePlants() takes too long to complete. Not sure how to go forward, would a different persistent storage method like core data be faster? Is storing a UIImage in my Plant class too much data?