Hey! In my last post, I mentioned that I am starting the 100 Days of SwiftUI this is a great way to learn SwiftUI. HackingWithSwift.org
The first 15 days are used to teach you the Swift basics that every SwiftUI developer needs. Because I felt comfortable with my experience of developing multiple Swift/ UIKit projects, the program allows you to skip the first 15 days. The first project is an app called WeSplit, a simple tip calculator that calculates each person’s amount. Also introducing how
The
The
My final take away from today is how this project is using
Today I continued learning how
@State private var checkAmount = ""
Before the View struct. Then by adding this code into the view body making sure to add
var body: some View {
Form {
Section {
TextField("Amount", text: $checkAmount)
}
}
}
By using the
The next step is to add a
var totalPerPerson: Double {
let peopleCount = Double(numberOfPeople + 2)
let tipSelection = Double(tipPercentages[tipPercentage])
let orderAmount = Double(checkAmount) ?? 0
let tipValue = orderAmount / 100 * tipSelection
let grandTotal = orderAmount + tipValue
let amountPerPerson = grandTotal / peopleCount
return amountPerPerson
}
This variable will return the value of the amount of the total plus tip, divided by the number of people.
The finish line is in sight for this project! The final thing to solve for is the last TextField that shows the total amount that each person owes.
When displaying the output, it will add more than the standard hundredths decimal value. This can be resolved using the
Section(header: Text("Total amount")) {
Text("$\(checkTotal, specifier: "%.2f")")
}
By using
Today is the final day of WeSplit. I feel excellent, and the project has been a joy to work on. I am learning some good fundamentals for SwiftUI. Additionally, I did the WeSplit review, which was a total of 12 questions, and I scored a very respectable 83%! I feel comfortable enough with my knowledge to accept the challenge of my first challenge day tomorrow. However, before I move on to the next project, there are three challenges to take the project further:
The first challenge is simply adding the header to the total amount section with the following code:
Section(header: Text("Amount per person")) {
TextField("Amount", text: $checkAmount)
}
The second challenge was a little bit more complicated. You would need to create a new variable that would calculate the amount due in total before dividing it up between the number of people and then displaying the result to a new
The third challenge stumped me at first. I ended up thinking it was more complicated than it was. After walking away and thinking about it, I realized the problem was quite simple. Similar to the amount field, you would take the String that is generated by the entered text and convert it to an
var totalPerperson: Double {
let peopleCount = Double(numberOfPeople) ?? 0
}
in the totalPerson variable.
Today is the first challenge day of the course. The challenge was to create an application that handles unit conversions. The types of conversion needed support are:
These challenges are crucial to making sure that you understand the complexities of Swift and SwiftUI. So with my long to-do list, I got started.
The interface is simple. Using the
This has been a fantastic week to learn and start developing using this new platform. I cannot wait to see what next week’s course work is. I am stopping at day four due to the transition to a new project starting tomorrow, and that deserves a fresh blog post. 🤗 Thanks for taking the time to read and keep up with my adventures in learning SwiftUI. See you next week!