#### Overview of this book

Elevate SwiftUI Skills by Building Projects helps you harness the cutting-edge potential of SwiftUI and its innovative and user-friendly approach to crafting user interfaces for Apple platforms with the power of Swift. This book will enhance your UI programming skills with SwiftUI through a project-based methodology, guiding you to create four real-world projects. Starting with a quick recap of Swift and SwiftUI, you’ll gradually develop projects tailored for iPhone, iPad, macOS, and watchOS using Swift and Xcode. You’ll experience SwiftUI’s versatility in action as you build a tax calculator for iPhone and a photo gallery for the iPad, which uses a larger display to enhance the viewing experience. You’ll also create an app store for Mac and, finally, get to grips with the power of SwiftUI for smaller devices such as the Apple Watch by designing a Fitness Companion app. By the end of this book, you'll have built fully functional projects across multiple platforms and gained the expertise needed to excel as a professional SwiftUI developer.
Chapter 1: Swift and SwiftUI Recap
Free Chapter
Chapter 2: iPhone Project – Tax Calculator Design
Chapter 3: iPhone Project – Tax Calculator Functionality
Chapter 4: iPad Project – Photo Gallery Overview
Chapter 5: iPad Project – Photo Gallery Enhanced View
Chapter 6: Mac Project – App Store Bars
Chapter 7: Mac Project – App Store Body
Chapter 8: Watch Project – Fitness Companion Design
Chapter 9: Watch Project – Fitness Companion UI
Index
Other Books You May Enjoy

# Validating salary input

As of now, if you press the Calculate Tax button, it takes the user to the results page from the front page. However, it does this regardless of input, so it will go to the next page even if there is no salary. The following validation checks must be done for it to be an acceptable value:

• Does it contain a value that is a number?
• Is the value above 0 (this rules out negatives)?

You might be wondering why we can’t just check whether the salary is above 0 as we have chosen a decimal keypad. There are two main reasons for this:

• The user can insert decimal points in a way that makes the input Not a Number (NaN) – for example, `4.5.6..`.
• Even though the user cannot directly type text due to the keyboard being a decimal pad, they can still copy it from another application and paste it into our calculator, thus breaking the number-only `TextField`. You may think it’s worth just disabling pasting but it’s important...