5-Day Swift Coding Challenge: Day 4

Apr 24 2025 · Swift 6.0, iOS 18, Swift Playground 4.6

Lesson 01: Day 4: Adding Interactivity

Demo: Adding Buttons

Episode complete

Play next episode

Next

Heads up... You’re accessing parts of this content for free, with some sections shown as obfuscated text.

Heads up... You’re accessing parts of this content for free, with some sections shown as obfuscated text.

Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.

Unlock now

For this app, you’ll present three programming languages. Users will vote for their favorite programming language by tapping the logo. When the user taps a logo, the counter beneath it will increase.

var csharp = 0
var kotlin = 0
var swift = 0
VStack {
    Button {
        // increase counter here
    } label: {
        Image("CSharp")
    }
    Text("\(csharp)")
        .font(.headline)
}
HStack {

}
VStack {
    Button {
        // increase counter here
    } label: {
        Image("Kotlin")
    }
    Text("\(kotlin)")
        .font(.headline)
}
VStack {
    Button {
        // increase counter here
    } label: {
        Image("Swift")
    }
    Text("\(swift)")
        .font(.headline)
}
.padding(.horizontal, 10)
Button {
    csharp = csharp + 1
} label: {
    Image("csharp")
}
csharp = csharp + 1
@State var csharp = 0
@State var kotlin = 0
@State var swift = 0
Button {
    kotlin = kotlin + 1
} label: {
    Image("kotlin")
}
Button {
    swift = swift + 1
} label: {
    Image("swift")
}
See forum comments
Cinema mode Download course materials from Github
Previous: Adding Buttons Next: Understanding State Updates