How to fix âReferencing initializer 'init(wrappedValue:)' on 'ObservedObject' requires that 'SomeType' conform to 'ObservableObject'â
2022ë
12ì 1ìŒ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