I need to create Array property of class witch is conform to ObservableObject protocol. Because I am going to use it with filter, sort and etc - to select records from table to show in List view
class SQS_Record: NSObject, ObservableObject {
@Published final var __idx: Int = -1
}
class Project: SQS_Record {
@objc dynamic var name: String = "" { willSet { objectWillChange.send() } }
}
class SQS_Table<RecordType: SQS_Record>: ObservableObject {
@Published var records = [RecordType]()
var rcount: Int {
return records.count
}
subscript (index: Int) -> RecordType {
get {
return records[index]
}
set(item) {
records[index] = item
}
}
Let projectsTbl = SQS_Table<Project>(...)
struct ProjectsListView: View {
// This is ERROR line - below
@StateObject private var itemsList = projectsTbl.records.sorted { $0.__idx < $1.__idx }
var body: some View {
NavigationView {
List() {
// Список
ForEach (itemsList, id: \.__id) { (proj: Project) in
ProjectElement(project: proj)
}
.onMove(perform: moveItem )
.onDelete(perform: delItem )
}
…
}
ERROR: Generic struct 'StateObject' requires that '[Project]' conform to 'ObservableObject'