Extending a Protocol that contains an array of Protocols in SwiftUI

Viewed 30

I am trying to create a struct that extends a Protocol called Pack. The Pack protocol has the following fields:

protocol Pack {
    var title: String { get set }
    var cards: [Card] { get set }
}

Where Card is also a Protocol (with all string fields).

I have a struct titled BaseballCard that properly implements the Card protocol. However, when I try making a struct BaseballPack that looks like this:

 var id: String
    var title: String
    var description: String
    
    var cards: [BaseballCard]

Xcode flags this as an error and says that BaseballPack does not conform to the Pack protocol. It is only happy if I give it a property like var cards: [Card].

However, BaseballCard correctly implements the Card Protocol. Any idea why this isn't allowed?

0 Answers
Related