Programming in Swift: Fundamentals

Oct 19 2021 · Swift 5.5, iOS 15, Xcode 13

Part 1: Core Concepts

07. Optionals

Episode complete

Play next episode

Next
About this episode

Leave a rating/review

See forum comments
Cinema mode Mark complete Download course materials
Previous episode: 06. Challenge: Logical Operators Next episode: 08. Challenge: Optionals

Get immediate access to this and 4,000+ other videos and books.

Take your career further with a Kodeco Personal Plan. With unlimited access to over 40+ books and 4,000+ professional videos in a single subscription, it's simply the best investment you can make in your development career.

Learn more Already a subscriber? Sign in.

Notes: 07. Optionals

Update Notes: The student materials have been reviewed and are updated as of October 2021.

Heads up... You've reached locked video content where the transcript will be shown as obfuscated text.

Optionals can be a point of confusion for beginners in Swift.

var petName: String
String?
petName = "Mango""
print(petName)
petName = nil
var result: Int? = 30
print(result)
print(result + 1)
var petName: String? = "Mango"
var petAge: Int? = 7
var unwrappedPetName = petName!
print("The pet's name is \(unwrappedPetName)")
var petName: String? = nil // "Mango"
if let unwrappedPetName = petName {

} else {

}
// type this above the if let
if petName != nil {
  let unwrappedPetName = petName
if let petName = petName {

if let petName = petName,
   let petAge = petAge {

} else {

}
    print("The pet is \(petName) and they are \(petAge)")
} else {
    print("No pet name or age")
var optionalInt: Int? = 10
var requiredResult = optionalInt ?? 0
 nil //10