Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

401
Visualizações
How Can I Pass Function Through A Toggle Swiftui

State var:

@State var toggleIsOn = false

Toggle:

Toggle(isOn: $toggleIsOn, label: {Text("Notifications")})

I want the following buttons, to represent each state of the toggle, on and off:

                // Will request to send notifications, if success; will schedule them.
                Button("request") {
                    NotificationManager.instance.requestAuthorization()
                }
                // Will clear the queue of notifications, and delete any delivered.
                Button("cancel") {
                    NotificationManager.instance.cancelNotifications()
                }

I found the functions in this video: https://www.youtube.com/watch?v=mG9BVAs8AIo

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

use

onChange(of:)

for example:

    struct ContentView: View {
    @State var toggleIsOn: Bool = false

    var body: some View {
        Toggle(isOn: $toggleIsOn, label: {Text("Notifications")})
        .onChange(of: toggleIsOn) { isOn in
             if isOn {
                  NotificationManager.instance.requestAuthorization()
             } else {
                  NotificationManager.instance.cancelNotifications()
             }
        }
    }
}
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda