To declare an @ObservedObject var, you need a type conforming to ObservableObject.
The protocol GalleryDataSource does inherit ObservableObject, but does not conform to ObservableObject.
Currently, there is no way provided to make protocols to conform some other protocol in Swift.
Better find another way.
One possible alternative would be using generics:
struct GalleryViewDataSource: GalleryDataSource: View {
@ObservedObject var dataSource: DataSource
var body: some View {
ScrollView(.horizontal, content: {
HStack {
ForEach(0..self.dataSource.itemCount, id:\.self) { index in
Text(dataSource.item(for: index))
.padding()
}
}
})
}
}
Topic:
UI Frameworks
SubTopic:
SwiftUI
Tags: