Our first complete Swift program is a Guess the Number app, a classic educational game for children where the player must guess a number generated randomly.
For each guess, the game tells the player whether the guess is greater or lower than the generated number (also called the secret number).
It is worth to remember that the goal here is not to build an App Store ready app with a perfect software architecture, but to show how to use Xcode to build apps for the iOS platform, so forgive me if the code is not exactly Clean Code, and if the game is trivial.
Before diving into the code, we must define the interface of the app and the expected workflow.
This game presents only one screen, which is shown in the following screenshot:
At the top of the screen, a label reports the name of the app, Guess a Number.
In the next row, another static label with the word, between, connects the title with a dynamic label that reports the current range. The text inside the label must change every time...