Thank you for the reply! I am following this tutorial here if this helps you understand my problem more, https://code.tutsplus.com/tutorials/ios-from-scratch-with-swift-building-a-shopping-list-application-1--cms-25515
It has grocery items in the array
Here is the code for the Item class, let me know if you need other code. Sorry I am a beginner so I'm unsure what is needed.
import UIKit
class Item: NSObject, NSCoding {
func encode(with coder: NSCoder) {
coder.encode(uuid, forKey: "uuid")
coder.encode(name, forKey: "name")
coder.encode(price, forKey: "price")
coder.encode(inShoppingList, forKey: "inShoppingList")
}
var uuid: String = NSUUID().uuidString
var name: String = ""
var price: Float = 0.0
var inShoppingList = false
// MARK: -
// MARK: Initialization
init(name: String, price: Float) {
super.init()
self.name = name
self.price = price
}
// MARK: -
// MARK: NSCoding Protocol
required init?(coder decoder: NSCoder) {
super.init()
if let archivedUuid = decoder.decodeObject(forKey:)("uuid") as? String {
uuid = archivedUuid
}
if let archivedName = decoder.decodeObject(forKey:)("name") as? String {
name = archivedName
}
price = decoder.decodeFloat(forKey:)("price")
inShoppingList = decoder.decodeBool(forKey:)("inShoppingList")
}
func encodeWithCoder(coder: NSCoder) {
coder.encode(uuid, forKey: "uuid")
coder.encode(name, forKey: "name")
coder.encode(price, forKey: "price")
coder.encode(inShoppingList, forKey: "inShoppingList")
}
}
Topic:
App & System Services
SubTopic:
General
Tags: