In my app i tried to make saving data with data persistence but i get this error: Must call a designated initializer of the superclass 'Day' error.
Here is my code:
class Day: NSObject, NSCoding { // NEMA NSCODING I NSOBJECT
var dayName: String
var subjects: [Subject]?
init(dayName: String) {
self.dayName = dayName
}
struct PropertyKey {
static var dayName = "dayName"
static var subjects = "subjects"
}
func encode(with aCoder: NSCoder) {
aCoder.encode(dayName, forKey: PropertyKey.dayName)
aCoder.encode(subjects, forKey: PropertyKey.subjects)
}
// Archiving paths
static let DocumentsDirectory = FileManager().urls(for: .documentDirectory, in: .userDomainMask).first!
static let ArchiveURL = DocumentsDirectory.appendingPathComponent("workingDays")//-namesto meals
required convenience init?(coder aDecoder: NSCoder) {
guard let dayName = aDecoder.decodeObject(forKey: PropertyKey.dayName) as? String else {
os_log("Unable to decode the dayName for a Day object.", log: OSLog.default, type: .debug)
return nil
}
let subjects = aDecoder.decodeObject(forKey: PropertyKey.subjects) as? [Subject]
self.init(dayName: dayName)
}
}
And here is the other class:
class Subject: Day {
var subjectName: String
var startsAt: String?
init(dayName: String,subjectName: String) {
self.subjectName = subjectName
super.init(dayName: dayName)
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder) // here I get the error
}
}
Am I going to save the data this way with implementing data persistence only in Day class and why do I get that error? I am a beginner and I'm doing it based on this apple documentation -
Any help would be much appreciated.