This project will help you practice the skills and concepts you learned related to Swift variables and constants, the print statement, as well as reviewing the things you learned in the last lesson.
- Create a new Xcode project
- Name the project "About Me"
- Make sure you select Swift as the development language
- Open the app's Main.storyboard file.
- Add a button to the main screen
- Make the button's title "Introduce Me"
- Use the Add Missing Constraints option to make sure the button is properly constrained
- Create an IBAction for the button in ViewController.swift
- Inside the IBAction, Create variables or constants for your name, your hometown, your favorite color and food, and anything else you think someone would be interested to know about you. Think about which of these should be variables, and which should be constants.
- Use
print()
statements to print each constant or variable.
- Build and run your app using the simulator
- Click the button and make sure your app prints your introduction to Xcode's console.
If you finish and want another challenge try the following:
- Add a text view to your app.
- Create an outlet from your view controller to the text view.
- In your button's IBAction, instead of using print statements, add your introduction text to the text view.
Hints: Look up string interpolation in Swift to learn how to turn variables into text. To put text in a text view use textView.text = string
where textView
is the name of your outlet, and string
is the string variable you create using string interpolation.
We will cover string interpolation in detail in a later lesson, so don't worry if you don't already know it, or find it confusing at first.