I want to have an optional @ObservedObject in SwiftUI but I keep getting a compile time error of.
Property type 'AModel?' does not match that of the 'wrappedValue' property of its wrapper type 'ObservedObject'
Here is some minimum reproducible code.
import SwiftUI
public struct AView: View {
//MARK: View Model
//Error thrown here.
@ObservedObject var model: AModel?
//MARK: Body
public var body: some View {
Text("\(model?.value ?? 0)")
}
//MARK: Init
public init() {
}
}
class AModel: ObservableObject {
let value: Int = 0
}
value
optional in AModel, that would be more doable thing! – NarcoanalysisOptional
is an enum - not a class, so it cannot conform toObservableObject
. – Polynesian