Cannot match Decoded or Encoded (Using Codable), even if the object being used matches

I am having issues with the compatibility of the two protocols using the Codable protocol.

I understand that even if I used a custom object, if this object successfully matches Codable, then any object referencing it can also match.

I have the following code and can't see why I am getting errors:

import UIKit
import Foundation

protocol PromotionProtocol: Codable {
    var promotionType: Int? { get }
    var promotionCode: String? { get }
    var fileName: String? { get }
    var facetDescription: String? { get }
    var promoDescription: String? { get }
}

class Promotion: PromotionProtocol {
    var promotionType: Int?
    var promotionCode: String?
    var fileName: String?
    var facetDescription: String?
    var promoDescription: String?
}

protocol PromotionInfoProtocol: Codable {
    var cornerPromotion: PromotionProtocol? { get }
    var mainPromotion: PromotionProtocol? { get }
    var isTopFive: Bool? { get }
}

class PromoInfo: PromotionInfoProtocol {
    var cornerPromotion: PromotionProtocol?
    var mainPromotion: PromotionProtocol?
    var isTopFive: Bool?
}

Everything inside "PromotionProtocol" is a string or an Int, so this is normal. But I get errors that Class Promotion does not match encoding and decoding.

+4
source share

Source: https://habr.com/ru/post/1687220/


All Articles