class Group: ObservableObject {
@Published var size: CGFloat = 22
}
struct content: View {
@ObservedObject var groups: [Group] = []
var body: some view {
.
.
.
}
}
above code error message :
Referencing initializer 'init(wrappedValue:)' on 'ObservedObject' requires that '[Group]' conform to 'ObservableObject'
I need array conformed to ObservableObject because i need to detect size property of Group in [Group]
How to make array of ObservableObject(ObservedObject)
I am not sure how to solve this problem directly but one way to solve your problem would be something like a GroupStore which holds your array. That could look like this:
class GroupStore: ObservableObject {
@Published private(set) var groups: [Group] = []
.
.
.
}
And then in your View you add the GroupStore property like this:
struct content: View {
@ObservedObject var groupStore: GroupStore
.
.
.
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With