Guard statements are an effective way of dealing with optional values, and allow you to set an optional to a nonoptional constant. See how it works here.
- [Instructor] I mentioned in a previous movie…that optionals allow you to call out variables…that can possibly be nil,…meaning that they don't have a value.…When you're using optionals, you have the choice to choose…between a question mark and an exclamation point…in calling them out.…Both have their advantages and disadvantages,…but what if there were a third way…where you could sort of get the best of both worlds?…I want to show you how that works…using something called a guard statement.…A guard statement checks to see…if the value of the variable is nil.…
If it is not nil,…it sets it to the value of a constant,…and so from then on you use…that new constant's value in your code.…But it's not optional on that case.…If the value of the variable is evaluated as nil,…then it runs an else statement,…and then you can run some code,…and you can stop moving forward.…So we have these options when we're working…with optional values.…So let's erase this print statement on line 19,…and I'm going to type out a guard statement.…
- Installing Xcode
- Creating an Xcode project
- Configuring the iOS Simulator
- Understanding variables
- Connecting visual objects to variables
- Understanding methods
- Connecting a button to a method
- Using conditional statements
- Setting up the user interface (UI)
- Building a complete iOS app
Skill Level Beginner
1. Set Up Your Coding Environment
Create an Xcode project4m 19s
2. Programming Building Blocks: Variables
3. Programming Building Blocks: Methods
4. Programming Building Blocks: Conditional Statements
5. Plan and Prepare the App
6. Build a Full Application
Next steps3m 11s
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.