What do Classes and Structures have in common?
What behaviors do classes have separate from structures?
What behaviors do structures have separate from classes?
2. Auto generated member-wise initializer for new instances.
What are “Optionals”?
A type that represents either. a wrapped value or “nil”.
Define “nil”
The absence of value.
When do you use an Optional?
If you cannot guarantee that a “prop”, “method”, or “subscript” will return a value.
How do you identify an Optional value?
With a trailing “?” after a type’s name. Ex: let sample = Int?
Is the Optional Type an enumeration?
Yes.
What are the two cases of the Optional Type?
Optional.none = "nil" literal Optional.some(wrappedValue) = storing a wrapped value.
What are the different ways you can unwrap an Optional?
What is Optional Binding?
Conditionally binding a wrapped value of an Optional Instance to a new variable; using a “Optional Binding Control Structure”.
What are the “Optional Binding Control Structures”?
“if let”, “guard let”, & “switch”
What is “Optional Chaining”?
Use (postfix ?) the postfix optional chaining operator to access the props and methods of a wrapped instance.
EX: (hasSuffix is the postfix operator)
if imagePaths[“star”]?.hasSuffix(“.png”) == true { print(….) }
What is Optional unwrapping with a “nil-coalescing operator”?
It provides a default value incase the optional value is “nil”. “??”
EX: let sample = answer1 ?? answer2
What is Unconditional Unwrapping (aka forced unwrapping) with optionals?
You have to been 100% certain that the instance contains a value.
Use the unwrap operator “!”
EX:
let number = Int("42")!This can also be used in chaining.
EX:
let number = path["sample"]!.hasSuffix(".png")What is an initializer?
Creates an instance that stores a given value.
EX: instanceName init(nilLiteral: () )