I'm facing an issue with codable. I'm not able to understand how to init custom timer object in codable class.
class ShelfItem: Codable {
var objTimer = Timer()
or i try to do it like
// var objTimer: Timer()
}
but it show me the error that is "Type 'ShelfItem' does not conform to protocol 'Encodable'"
var objTimer = Timer()doesn’t make sense (a timer with no handler and no specified time to fire). Andvar objTimer: Timer()is just syntactically incorrect. But let’s set that aside and ask what you’re expecting to be encoded: As vadian said, it doesn’t make sense to encode/decode aTimer, itself, so you’d either exclude it from coding or take the unusual step to encode/decode enough so the timer could be reconstituted later (which is a strange notion with timers). Perhaps you can describe why you’re trying to encode/decode a timer and describe what you’re hoping to achieve.