Optionals are a special type of variable that can possibly be nil, or have no value. This video explains why optionals exist and how to use them in your code.
- [Instructor] Sometimes, you don't have the value…of the variable at the time that you create it.…Imagine creating a form where you're going to collect…a user's name and you need to have the variable…to do something with their name after they enter it.…But at the time that you write your code,…before the application runs, you actually…don't have their name right away.…In those cases, you need to be able to create…a type of variable that can possibly not have a value.…
So let's look at how that works in swift.…So right underneath my class declaration,…I'm going to create a few lines…and I'm going to create a variable called name.…And it's going to be of the type string,…so :String with a capital S.…Now we've done this before, we know…that a string is a text value.…But let's say we can't give this a value just yet…because we don't know the person's name…until our app is actually going to be running.…Well, to say that this could possibly not have a value,…we need to call it out specifically in swift.…
And we do that with a question mark.…
- 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.