I am getting the above compiler error on the following class:
class Log: NSObject, NSCoding {
var targetHoursPerWeek: Double
var weeksLog: Double[]
// Serialization keys that are using to implement NSCoding.
struct SerializationKey {
static let targetHoursPerWeek = "targetHoursPerWeek"
static let weeksLog = "weeksLog"
}
init() {
targetHoursPerWeek = 7.0
weeksLog = Double[](count: 7, repeatedValue: 0.0)
// [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
}
// MARK: NSCoding
init(coder decoder: NSCoder) {
targetHoursPerWeek = decoder.decodeObjectForKey(SerializationKey.targetHoursPerWeek) as Double
weeksLog = decoder.decodeObjectForKey(SerializationKey.weeksLog) as Double[]
}
func encodeWithCoder(encoder: NSCoder) {
encoder.encodeObject(targetHoursPerWeek, forKey: SerializationKey.targetHoursPerWeek)
encoder.encodeObject(weeksLog, forKey: SerializationKey.weeksLog)
}
}
I believe that the error comes from the line
weeksLog = decoder.decodeObjectForKey(SerializationKey.weeksLog) as Double[]
but if so I am stumped -- the "as Double[]" agrees with the declaration of "weeksLog". So I am stumped!