Home > AI > IOS > SwiftUI >

onReceive(_:perform:)

Example

struct ContentView: View {
    let timer = Timer.publish(every: 1, on: .main, in: .common).autoconnect()

    
    var body: some View {
        Text("Hello, World!")
            .onReceive(timer) { time in
                print("The time is now \(time)")
            }
    }
}

Leave a Reply