I posted this question with error message as title. got no help.
I am programmer with 20 years experience. but new to Swift Programming. So sorry, my terminology could be different / misleading.
I am navigating to different page view based on user action.
NavigationLink {
DisplayView(input_parameter: dispTab, isNew: false)
}
dispTab is an Array or Row (1 line entry from a table). it has many attributes.
one of the attribute,
dispTab.itemKey is defined as UUID.
I wanted to use dispTab.itemKey and fetch entries from database table.
could you help me with the code, please.
Here is the code I used, but it is giving me errors.
@Environment(\.managedObjectContext) private var viewContext
@FetchRequest(
sortDescriptors: [NSSortDescriptor(keyPath: \LabelsItem.date, ascending: false)],
predicate: {
guard let currentUserId = AppSession.shared.currentUserId else {
return NSPredicate(value: false)
}
return NSPredicate(format: "userId == %@ AND itemKey == %@", currentUserId as CVarArg, input_parameter.itemKey as CVarArg)
}(), // Immediately invoke the closure
animation: .default
) private var itab: FetchedResults<ItemTable>
When I can use currentUserId (Global Variable) with no issues.
I don't know why I can't use input_parameter.itemKey.
I am able to "display" every attribute from input_parameter. but i can't use it to fetch the entries.
Could you please help.
Error is:
Cannot use instance member 'input_parameter' within property initializer; property initializers run before 'self' is available