I'm having some trouble with conforming 2 protocols together using the Codable protocol.
My understanding is that even if I used a custom object, as long as that object successfully conforms to Codable, then any object referencing that can also conform.
I have the following code and cannot see why I am getting the 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 the 'PromotionProtocol' is either a String or Int so that is fine. But I get the errors that the Class Promotion does not conform to Encodable and Decodable.