Join Harrison Ferrone for an in-depth discussion in this video Booleans, part of Learning Swift 3 for Developers.
- [Harrison] Let's make a little bit more room…underneath our string section,…and add our title comment.…I'm going to call this Booleans and Bang Operators.…A boolean variable can only have two values, true or false.…These are most often used…when dealing with logic or control flow…as in managing if/else statements…or setting flags to keep track of state.…Let's consider a case where, say, we want to keep track…of when an image has finished loading from the web.…
We could start by declaring a boolean with the value false.…Let's start with var imagesHaveFinishedLoading…equals false.…Now when the image has finished loading,…we could set its value to true,…however, we could also use the bang operator…to simply toggle our variable back and forth.…Let's try that right now.…imagesFinishedLoading equals…exclamation mark, imagesFinishedLoading.…
The bang operator or exclamation mark here…is setting imageFinishedLoading to its opposite value.…This is really helpful…in cases where you don't want to have to keep track…of the actual true or false values.…
- Starting a new playground
- Printing to the console
- Declaring variables
- Working with numbers
- Using strings
- Breaking down optionals
- Understanding closures
- Classes vs. structs
- Extensions and protocols
Skill Level Beginner
1. Hello Swift
2. Back to Basics: Variables and Operators
3. Collections, Tuples, and Enumerations
4. Working with Logic Flows
5. Only in Swift: Optionals
6. Functions, Closures, and Associated Types
7. Classes vs. Structs
8. Advanced Topics
- 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.