Posts

Post marked as solved
2 Replies
389 Views
I am calling JobOverView from two spots in JobsView. One is in a NavigationLink and works as expected. The other is in the addJob function and it doesn't work much at all. For one, it gives a warning that I'm not doing anything with the return value. What return value? I'm assuming its trying to return a view but why only here and not in the nav link? In any case, I can silence it with let _ =. When I call it in addJob and trace through in the debugger it bounces around the variables I declare in JobOverView but never gets to the body at all. Is there another way I should be going about this? The code: SwiftUI struct JobsView: View { @Environment(\.managedObjectContext) private var viewContext @FetchRequest( sortDescriptors: [NSSortDescriptor(keyPath: \Job.timestamp, ascending: true)], animation: .default) private var jobs: FetchedResultsJob var body: some View { NavigationView { List { ForEach(jobs) { job in NavigationLink ("\(job.name!)") destination: JobOverView(job: job)) } .onDelete(perform: deleteJobs) } .toolbar { Button(action: addJob) { Label("Add Job", systemImage: "plus") } } .navigationTitle("Jobs") } } private func addJob() { withAnimation { let newJob = Job(context: viewContext) newJob.timestamp = Date() do { try viewContext.save() } catch { let nsError = error as NSError fatalError("Unresolved error \(nsError), \(nsError.userInfo)") } let _ = JobOverView(job: newJob) } } } SwiftUI struct JobOverView: View { @State var jobEditState = JobEditState.closed @ObservedObject var job: Job var body: some View { VStack { HStack { if jobEditState == .closed { Button(action: { jobEditState = .info }) { Label("Job Info", systemImage: "chevron.down.circle.fill") Spacer() } .padding(.leading) } else if jobEditState == .info { JobInfoView(job: job, jobEditState: $jobEditState) } else if jobEditState == .editing { JobEditView(job: job, jobEditState: $jobEditState) } } List { ForEach(job.roomsArray) { room in NavigationLink (destination: RoomEditView(room: room)) { RoomView(room: room) } } .onDelete(perform: deleteRooms) } }
Posted
by Dramey.
Last updated
.