Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

402
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda