iOS Flashcards
What are the 4 Obj-C Data Types?
- Bool
- NSInteger
- NSUInteger
- NSString
Name 6 key features of Swift
- Type Safety
- Simplicity
- Readability
- Multiplatform support
- Open source
- Obj-C Compatible
What are the pieces that make up an NSError object?
- Error Domain
- Error Code
- Application specific user info
Explain what an Enum is
Variable with user defined values that can be used in a type safe way with switches and conditionals
What does the lazy keyword mean?
The property defined as lazy will not be computed until its called
What is a generic is swift?
A function or class that that does not infer type to allow for reusability
What does KVC mean and do?
Key value constant. Allows access of properties via string instead of property names
What does KVO mean and do?
Key Value Object: allows other objects to observe changes to the specified object
What are the 3 steps of Test Driven Development?
Fail
Pass
Refactor
What does a completion handler do?
Calls a function when a task completes
What are the 4 types of queues?
Dispatch
Serial Dispatch
Concurrent Dispatch
Main Dispatch
What does a dispatch queue do?
A dispatch queue is responsible for executing a task in the first-in, first-out order.
What does a serial dispatch queue do?
A serial dispatch queue runs tasks one at a time.
What does a concurrent dispatch queue do?
A concurrent dispatch queue runs as many tasks as it can without waiting for the started tasks to finish.
What’s does the main dispatch queue do?
A globally available serial queue that executes tasks on the application’s main thread.
What are 6 types of pattern matching in Swift?
Tuple pattern Type Casting Wildcard Optional Enumeration Expression
What is tuple pattern matching?
used to match values of corresponding tuple types.
What is type-casting pattern matching?
allow you to cast or match types
What is wildcard pattern matching?
match and ignore any kind and type of value
What is optional pattern matching?
used to match optional values
What is enumeration pattern matching?
match cases of existing enumeration types.
What is expression pattern matching?
allow you to compare a given value against a given expression.
What are 3 benefits of guard statements?
- Safely unwrap optionals
- Avoid if let pyramids
- Provides an early exit of the function
Name 3 debugging tools in Xcode
- View debugger
- Thread sanitizer
- Memory graph debugger
What is the difference between a public class and an open class?
Open classes can be overidden in a subclass. Public classes allow access but no subclassing or overriding
What are the 9 steps in a the view lifecycle order (in order)?
- loadView
- viewDidLoad
- viewWillAppear
- viewWillLayoutSubviews
- viewDidLayoutSubviews
- viewDidAppear
- viewWillDisappear
- viewDidDisappear
- viewWillTransition(to:with:)
What are the 5 states of an application?
- Non-running
- Inactive
- Active
- Background
- Suspended
Explain the key points to how ARC works
ARC is automatic reference counts. It tracks the references to a given object In memory. When an object’s ARC is 0, its removed from memory
How are value types managed in memory? Does ARC need to need to be used?
Swift automatically handles value types. Value types are not managed by ARC
What is a retain cycle?
The number of references to an object in ARC does not equal 0 and therefore cannot be removed from memory. If 2 strong objects are referencing each other, they will be never be removed from memory.
What is another name for a circular reference?
A retain cycle and circular reference are the same thing
Will a weak reference increase an ARC count?
No
Will a strong reference increase an ARC count?
Yes
What type are classes?
A reference type
What type are structs?
A value type
What advantage does a class have over a struct?
Classes can inherit from other classes and can be used with identity operators
What advantages does a struct have over a class?
Doesn’t require inheritance and a simple data type
How does a value type handle its data?
Each copy of a value type is unique and data changes are unique to that instance
How does a reference type handle its data?
Each copy of the reference shares data. A change made to one is shared to the other references.
What type is a closure?
Reference type
What are the 7 ways to unwrap an optional?
- Forced unwrapping
- Implicitly unwrapped (don’t specify variable type)
- Optional binding (if let)
- Optional chaining (x?.count)
- Nil coalescing operator (x ?? “”)
- Guard statement
- Optional pattern (if case let a? = x)
What is a protocol in Swift?
- A style that defines set blueprint of methods, variables, etc. Other classes, structs and enums can then implement them, conforming to the protocol and providing expected consistency
What is the difference between a stored property and a computed property?
- Stored: variables or constants that store values to the instance of the object
- Computed: Does not store values, but used getter and setter to fetching and storing values via computation usually
Where can a stored variable be used?
Classes and structs
Where can a computed value be used?
Classes, structs and enums
How do you change an internal state of a struct using a function?
Mark the function as mutating
What does the keyword static mean in a class?
It can not be overridden
What is the difference between Nil and .none?
They are the same. Nil is preferred convention