I have this error. I know some people have answered this on other threads but the answers given did not seem to work for me.
Here is my code:
The People class:
class People: NSObject, NSCoding {
var firstName : String
var lastName : String
var events : [Event]
init(firstName: String, lastName: String) {
self.firstName = firstName
self.lastName = lastName
self.events = []
}
required init (coder aDecoder: NSCoder) {
firstName = aDecoder.decodeObject(forKey: "firstName") as! String
lastName = aDecoder.decodeObject(forKey: "lastName") as! String
events = aDecoder.decodeObject (forKey: "events") as! [Event]
}
func encode(with aCoder: NSCoder) {
aCoder.encode(firstName, forKey: "firstName")
aCoder.encode(lastName, forKey: "lastName")
aCoder.encode(events, forKey: "events")
}
}
Here is where I call to save the file:
func SaveMyPeople(){
let Defaults = UserDefaults.standard
let SavedData = NSKeyedArchiver.archivedData(withRootObject: ArrayPeople)
Defaults.set(SavedData, forKey: "People")
}
This is the Event Struct:
struct Event{
var date : String
var message : String
}
Any help I can get will be very much appreciated
super.init(coder: aDecoder)inrequired init?(coder aDecoder: NSCoder)and also missing the?in the signature of thatinit.