UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

Updating CoreData after home screen Quick Action

Forums > SwiftUI

I add students to my app with a modal view, using "onDismiss" option to call a function just after doing so, to update data with sorting and filtering parameters, as follows:

.sheet(isPresented: $showingAdd, onDismiss: {
      checkData(order: orderedBy)
    }){
      StudentAddView()
   }

...

func checkData(order: String) {

    filteredStudents = studentSearch(query: query)
    filteredStudents = filteredStudents.filter { $0.marked == markedFilter }

    switch order {
    case "student" :
      filteredStudents = filteredStudents.sorted(by: { ($0.name ?? "") < ($1.name ?? "") })
    case "instrument" :
      filteredStudents = filteredStudents.sorted(by: {
        ($0.relatedInstrument?.name ?? "") < ($1.relatedInstrument?.name ?? "") })
     ...
    }
  }

Users can add students directly from app icon, also, with a quick action. My problem is that, in this case, as "add student" quick action is handled directly by @main view, I can't call this "checkData" function, as its parameters ("query", "markedFilter"...) are not defined there.

How could I workaround with this issue? Thanks.

1      

BUILD THE ULTIMATE PORTFOLIO APP Most Swift tutorials help you solve one specific problem, but in my Ultimate Portfolio App series I show you how to get all the best practices into a single app: architecture, testing, performance, accessibility, localization, project organization, and so much more, all while building a SwiftUI app that works on iOS, macOS and watchOS.

Get it on Hacking with Swift+

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.