DEV Community

Saurabh Chavan
Saurabh Chavan

Posted on • Updated on

How Button & function work in swiftUI

When we click on the button then value will update on the screen

import SwiftUI

struct ContentView: View {
    @State private var name = ""

    var body: some View {
            Button("click me",role: .destructive, action: Clicked).buttonStyle(.borderedProminent).tint(.green).foregroundColor(.black)
            Text("Hello \(name)")

      func Clicked(){
               name = "Saurabh"


struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
Enter fullscreen mode Exit fullscreen mode


Image description

Top comments (0)