How to fix “Referencing initializer 'init(wrappedValue:)' on 'ObservedObject' requires that 'SomeType' conform to 'ObservableObject'”
About 2 min
How to fix “Referencing initializer 'init(wrappedValue:)' on 'ObservedObject' requires that 'SomeType' conform to 'ObservableObject'” 관련
SwiftUI by Example
Back to Home
How to fix “Referencing initializer 'init(wrappedValue:)' on 'ObservedObject' requires that 'SomeType' conform to 'ObservableObject'” | SwiftUI by Example
How to fix “Referencing initializer 'init(wrappedValue:)' on 'ObservedObject' requires that 'SomeType' conform to 'ObservableObject'”
Updated for Xcode 15
This error happens because you’re trying to use the @ObservedObject
property wrapper on a type that doesn’t conform to the ObservableObject
protocol. For example, you have a type like this:
class User {
@Published var name = ""
}
And you use it in a view like this:
struct ContentView: View {
@ObservedObject var user: User
var body: some View {
Text(user.name)
}
}
To fix the problem, simply add the ObservableObject
conformance to your type, like this:
class User: ObservableObject {
@Published var name = ""
}
Similar solutions…
How to fix “Initializer 'init(_:rowContent:)' requires that 'SomeType' conform to 'Identifiable'” | SwiftUI by Example
How to fix “Initializer 'init(_:rowContent:)' requires that 'SomeType' conform to 'Identifiable'”
How to fix “Fatal error: No ObservableObject of type SomeType found” | SwiftUI by Example
How to fix “Fatal error: No ObservableObject of type SomeType found”
What's the difference between @ObservedObject, @State, and @EnvironmentObject? | SwiftUI by Example
What's the difference between @ObservedObject, @State, and @EnvironmentObject?
What is the @ObservedObject property wrapper? | SwiftUI by Example
What is the @ObservedObject property wrapper?
How to use @ObservedObject to manage state from external objects | SwiftUI by Example
How to use @ObservedObject to manage state from external objects