Classes vs. Structs
A: The main difference is that classes are reference types and structs are value types.
When you pass a class through a function or assign it to a variable, it will increase its reference count.
When you pass a struct through a function or assign it to a variable, its value is copied instead of increasing its reference count.
A good analogy is comparing a google doc to a word doc. When you send someone a word doc they’re able to edit a copy of the document, this is like a struct. And when you send someone a google doc then you’re both able to edit the same document, just like a class.
Other differences are: classes have inheritance, type casting, & de-initializers .
ARC, Retain Cycles, & Memory Leaks
A: Swift uses Automatic Reference Counting to handle memory management.
A: Automatic Reference Counting keeps track of strong references to instances of classes. It increases or decreases their reference count whenever you assign or unassign them to constants, properties, or variables. Memory only gets deallocated whenever the reference count reaches zero.
A: A memory leak is when an amount of allocated space in memory cannot be deallocated due to a retain cycle.
A: A retain cycle occurs when two or more objects hold strong references to each other. As a result these objects retain each other in memory because their retain count never reaches zero.
A: You can prevent a retain cycle by using ‘weak’ or ‘unowned’ references. A good example of this would be using [weak self] in a closure.
A: Weak references are allowed to be nil. Unowned references are never nil.
A: The easiest way to detect a memory leak is by using the debug memory graph. If the memory usage keeps increasing and never decreases then that’s an indicator that you might have a retain cycle.
Observer & Delegation
Work in-progress
A: The delegation design pattern enables an object to delegate some of its responsibilities to another object. The delegating object typically keeps a reference to the other object.
A: The delegate variable has to be declared as ‘weak’ to avoid a retain cycle.
A: The most common place where we use the delegation pattern in iOS development would be with TableViews & CollectionViews.
A: The Observer Design Pattern allows an object to notify other objects about changes in its state.
A: TODO://
A: The delegation design pattern is a one-to-one relationship, meaning one object communicates with one other object & the observer pattern is a one-to-many relationship, meaning one object can communicate with multiple other objects.
MVC & MVVM
Work in-progress
Static & Singletons
Work in-progress
Access Controls
Work in-progress
3rd Party Libraries
Work in-progress
Data Persistence
Work in-progress
App & VC Lifecycle
Work in-progress
Frames vs. Bounds
Work in-progress
Networking
Work in-progress
Swift Fundamentals
Work in-progress
Testing
Work in-progress
Recruiter Phone Screen
Work in-progress
Feel free to create issues for questions you want answered.
If you already have a good answer then you can submit a pull request.
James Sedlacek created this to help minimize the amount of time it takes to study for iOS interviews.