iOS Development Flashcards
What do Classes and Structures have in common?
- Define props to store values.
- Define methods for functionality.
- Define subscripts to access their values - using subscript syntax.
- Define initializers to setup state.
- Extend functionality beyond their default implementation.
- Conform to protocols for standard functionality.
- Contain Stored props as variables &/or constants.
- Use initializer syntax for new instances.
- Use dot notation to assign a new variable value or access props from their instances.
What behaviors do classes have separate from structures?
- Ability for inheritance.
- Type-casting.
- Ability for de-initializing.
- Reference counting (1+ reference to a class instance).
- Is a “reference type”.
What behaviors do structures have separate from classes?
- Considered a “value type”.
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?
- Binding
- Chaining
- “Nil-Coalescing-Operator”
- Unconditional
- Forced
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")