Build a Basic Counter App with SwiftUI in Xcode 11
2 min readJun 25, 2019
Objective: Today you will create a SwiftUI app with State in SwiftUI to create an awesome counter app.
My name is Maxwell, and I run the maxcodes.io iOS Dev Newsletter. Nice to finally meet you.
Step 1 — Create a Single View App in Xcode 11
- create a single view app
- make sure Use SwiftUI is selected when creating the project
Step 2 — Create an aligned VStack
- change the default text to say current count: 0
- wrap the text with VStack and add an alignment of leading
Step 3 — Replace 0 with a State Variable
- Create a state variable called count
- use string interpolation in the text to display that value
the output should not change.
Step 4 — Create a Button to increment the count State variable.
- Create a Button and add a Text label
- Increment count += 1 each time the button is pressed
Now, each time you press the button, the current count text will display the previous number plus one.
That’s it!
You’ve now created a SwiftUI counter application using the following tech
- Text
- VStack & Alignment
- Button & Action
- String Interpolation
But I want to learn more Maxwell!
No problem, I have three resources for you fam.
- Free SwiftUI Content on my YouTube Channel.
- The Complete SwiftUI Course On Udemy.
- Join the Free iOS Developer Newsletter
As Always, Thank You.
Your support helps me help you :)
Max