My project is a universal app with iOS 15 and macOS 12 targets, to attempt to take advantage of latest technologies, including SwiftUI and Table
.
I let Xcode take care of the CodeGen by selecting type "Class Definition" and then write Extensions
for custom properties.
I have an entity named Event
with a class name PTG_Event
. Each Event
can have a number of actions and so each Event
also has a one-to-many relationship with Action
(class PTG_Action
).
I am attempting to use Table
to display the actions for each event... but this doesn't work...
struct ActionTable: View { @ObservedObject var event: PTG_Event @FetchRequest(entity: PTG_Action.entity(), sortDescriptors: [] ) var eventActions: FetchedResults<PTG_Action> @State var sortOrder: [SortDescriptor<PTG_Action>] = [ .init(\.dateCommences, order: SortOrder.forward) ] var body: some View { let events = eventActions.filter { $0.event == event } Text("Action Table") Table(events, sortOrder: $sortOrder) { TableColumn("Ref", value: \.reference) { action in Text(action.reference ?? "NO REF") } TableColumn("Date", value: \.dateCommences) { action in Text(action.dateCommences?.formatted(date: .abbreviated, time: .omitted) ?? "NO DATE") } } } }
I have attempted many variations on this.
Any suggestions?