iOS Development Flashcards

1
Q

What do Classes and Structures have in common?

A
  1. Define props to store values.
  2. Define methods for functionality.
  3. Define subscripts to access their values - using subscript syntax.
  4. Define initializers to setup state.
  5. Extend functionality beyond their default implementation.
  6. Conform to protocols for standard functionality.
  7. Contain Stored props as variables &/or constants.
  8. Use initializer syntax for new instances.
  9. Use dot notation to assign a new variable value or access props from their instances.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What behaviors do classes have separate from structures?

A
  1. Ability for inheritance.
  2. Type-casting.
  3. Ability for de-initializing.
  4. Reference counting (1+ reference to a class instance).
  5. Is a “reference type”.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What behaviors do structures have separate from classes?

A
  1. Considered a “value type”.

2. Auto generated member-wise initializer for new instances.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What are “Optionals”?

A

A type that represents either. a wrapped value or “nil”.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Define “nil”

A

The absence of value.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

When do you use an Optional?

A

If you cannot guarantee that a “prop”, “method”, or “subscript” will return a value.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How do you identify an Optional value?

A

With a trailing “?” after a type’s name. Ex: let sample = Int?

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Is the Optional Type an enumeration?

A

Yes.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What are the two cases of the Optional Type?

A
Optional.none = "nil" literal
Optional.some(wrappedValue) = storing a wrapped value.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What are the different ways you can unwrap an Optional?

A
  1. Binding
  2. Chaining
  3. “Nil-Coalescing-Operator”
  4. Unconditional
  5. Forced
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is Optional Binding?

A

Conditionally binding a wrapped value of an Optional Instance to a new variable; using a “Optional Binding Control Structure”.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What are the “Optional Binding Control Structures”?

A

“if let”, “guard let”, & “switch”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is “Optional Chaining”?

A

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(….) }

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is Optional unwrapping with a “nil-coalescing operator”?

A

It provides a default value incase the optional value is “nil”. “??”

EX:  
let sample = answer1 ?? answer2
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is Unconditional Unwrapping (aka forced unwrapping) with optionals?

A

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")
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is an initializer?

A

Creates an instance that stores a given value.

EX:
instanceName init(nilLiteral: () )