I'm learning Swift — from the language docs, it seems to me that this should be possible, but I get the commented compiler error on the line below. Can someone explain why this is illegal?
import SwiftUI
struct ContentView: View {
// 'init(wrappedValue:)' is unavailable: The wrapped value must be an object that conforms to Observable
@Bindable var failing : SomeProtocol
var body: some View {
Text(failing.foo)
}
}
protocol SomeProtocol : Observable {
var foo: String { get }
}
The use case is adapting different class hierarchies to be displayed by the same View: final SwiftData model classes and dynamic models supporting editing and calculation during model creation.
Apple docs on Observation and Protocol Inheritance have led me to believe this should be possible.
Thanks for taking time to read (and reply).