Post

Replies

Boosts

Views

Activity

Reply to Picker in SwiftUI Form Selection
I may have gotten a solution to this. Its not entirely what I was looking for but it does work. Picker("Category", selection: $eCategoryName) { ForEach(cats, id: \.self) { Text($0).tag($0) } } //.pickerStyle(.navigationLink) .onAppear { if !pickerLoaded { if let firstCategory = cats.first { eCategoryName = firstCategory pickerLoaded.toggle() } } } The first time the picker is loaded the selected value is set to the first category in the array. Form validation works because now there's a value in the selected variable. Because the first one is selected, the fact that the first item is checked is irrelevant. Thanks!
Apr ’23
Reply to Conditionally showing List or other views
So I worked out a solution. Its kind of kludgy but it works. I'd appreciate any comments or alternative solutions. struct CalendarView: View { @StateObject var selectedDate = SelectedDate() @Environment(\.managedObjectContext) private var viewContext @FetchRequest( sortDescriptors: [NSSortDescriptor(keyPath: \Expense.eName, ascending: true)], animation: .default) private var expenses: FetchedResults<Expense> @State private var listIsVisible:Bool = false var body: some View { VStack { CalendarHelper(interval: DateInterval(start: .distantPast, end: .distantFuture), date: selectedDate) ForEach(expenses, id:\.self) { exp in if selectedDate.selectedDate.isInSameDay(as: exp.eDueDate ?? Date()) { List { ExpenseRowItemView(eName: exp.eName ?? "", eCategory: exp.eCategoryName ?? "", eDueDate: exp.eDueDate ?? Date(), eImageName: exp.eCategoryName ?? "", showEdit: false) }.onAppear(){listIsVisible = true} } else { Text("") .hidden() .onAppear(){listIsVisible = false} } } if !listIsVisible { VStack { GeometryReader { geometry in Image("emptyView") .resizable() .aspectRatio(contentMode: .fit) .frame(width: geometry.size.width, height: geometry.size.height) } Text ("No Data") .onAppear(){listIsVisible = false} Spacer() } } } } } Thanks!
Apr ’23