What is ARC?
Automatic reference counting:
What are the main differences between classes and structs in Swift?
Struct is value type (Stack); Class is reference type (Heap – slower in performance).
When you copy a struct, you end up with two unique copies of the data.
When you copy a class, you end up with two references to one instance of the data
Structs do not support inheritance but can adhere to protocols. Classes support inheritance.
What is the delegation pattern?
Delegation allows you to have one object delegate a task to another object. For example, having a viewcontroller provide the datasource for a UITableView
Explain MVC
Architecture approach that separates code into models, views, and controllers. Controllers generally handle the logic and act as an interface between the model and the view. Problem is with “massive view controllers”. For example if your view required date formatting, where should that formatting occur? Frequently dumped into the controller.
Explain MVVM
Model-view-viewmodel. Architecture approach that is similar to MVC but creates a viewModel layer for handling view logic. For example if your view required date formatting, then the viewmodel would be a good place for the date formatting to occur. This allows for lean view controllers and plays nice with reactive architectures, can setup all bindings in VC and then all logic happens in VM.
Explain Dependency Injection and give an example
DI is a pattern where we provide an object’s dependencies to it, instead of having this object seek out it’s dependencies. For example, if our VC needs a network service, then we can pass that networking object into the VC’s init. Benefits of this include: easier for testing, cleaner code, and less tightly coupled code.
What are the benefits of dependency injection?
What is a retain cycle? Give an example
A retain cycle occurs when two objects are holding references to each other. Common example is when you reference self inside of a closure.
How to identify a retain cycle?
Use instruments tool or memory debug graph in xcode
Describe the view lifecycle
Describe the different access modifiers
When do we need an escaping closure?
If the closure is called after the function is returned, like after a networking delay, it must be marked as escaping
How would you improve UITableView scroll performance?
What is GCD?
low level api that allows users to run concurrent tasks, multithreading
Describe the different app states
If the user were to scroll really quickly, what would happen in the cells? Would they all show the correct image?
Which thread must UI work be done on?
Main
What is a memory leak?
When an object that should be deallocated, has not been deallocated
How would you describe the swift language?
type-safe, can be used for scripting, or programming, across mobile, desktop, and sever. Can leverage protocols, and reactive functional paradigms
When would you use a DispatchGroup?
Dispatch groups are good for when we want to perform more than 1 time consuming operations before proceeding with some logic. For example, if we need to make multiple different requests to build a model, we can group those requests to simplify the order of events
What are locks in regards to GCD?
Locks prevent race conditions by requiring that a thread have a lock to access a piece of code. Threads w/o the lock cannot access that code.
What design patterns are you familiar with?
Explain the diff between strong and weak pointers
https://www.appypie.com/weak-vs-strong-references-swift
Why do we use weak references? Give some examples
https://www.appypie.com/weak-vs-strong-references-swift