I have
protocol Model: Identifiable where ID == String? {
var id: Self.ID { get set }
}
struct WidgetModel: Model {
var id: String?
}
struct ContentView: View {
let models = [any Model]()
var body: some View {
//example 1
ForEach(models) { _ in
}
//example 2
.sheet(item:model) {
}
}
}
but gives compiler errors that
Type 'any Model' cannot conform to 'Identifiable'
According to this discussion the compiler might have a hard time because it doesn't know the type of ID but I specifically told it that it would be String
If this is a swift limitation at this point, how can I work around this? I need to have an array of the protocol because essentially I'm iterating mixed concrete types. I've seen a solution mentioned in that thread where you extend ForEach to get over this but this is not an option because there are plenty of other places where SwiftUI expects an identifiable without allowing you to specify id (.sheet as just one example).