This project will help you practice the skills and concepts you learned related to logical comparison operators, Boolean operators, and Optionals in Swift.
Unlike the previous two projects, this project is all done in playgrounds. Follow the instructions below:
- Download the playground for this project by clicking here.
- Unzip the downloaded file.
- Open the included ConditionalsAndOptionals.playground file using Xcode
This project consists of multiple pages. You can see all the pages by choosing View->Navigators->Show Navigators in the View menu in Xcode.
- Complete all the excercises on the first page.
- Go to the next page by clicking the "Next" link at the bottom of the playground, or by selecting it in the files navigator on the left side.
- Repeat until you've completed all pages in the playground.
If you finish and want another challenge try the following:
- Open your Flashlight project from day 1.
- Modify the project so that when the "Turn Flashlight On" button is clicked, the screen turns bright if the current time is between the hours of 8 AM and 10 PM. If the the current time is between the hours of 10 PM and 8 AM (night time), make the screen gray instead.
Hint: You can get the current hour (in 24-hour time) using the following snippet of code. Note that hour
here is an Int?
.
let calendar = Calendar(identifier: .gregorian)
let currentDate = Date()
let hour = calendar.dateComponents([.hour], from: currentDate).hour
This code includes syntax and concepts we haven't covered yet. It's OK for you to copy and paste it to use it now. You'll learn enough to understand it later.
Zip up the ConditionalsAndOptionals.playground file after you've finished all the excercises. Submit the zipped playground file to your project manager (PM).