It’s a New Year!
Perhaps you are looking for a new job, or are thinking about upgrading your developer self.
Why not use this quick list of Interview Questions and Answers?
Hand-picked and selected for 2021, these are the terms and questions that you need to know for your iOS dev role!
app ID / bundle ID App ID identifies one or more Apps from a development team. Bundle ID uniquely identifies each App. AppID is local, BundleID is on Apple’s side.
Access control open, public, internal, fileprivate and private.
App states not running, inactive, active, background and suspended. Not running — not launched, inactive is foreground but not receiving events (transitioning states), active is normal, background is executing code, suspended is in the background not executing code.
automic and nonatomic synthesized properties automic thread safe and slow, nonatomic multiple threads.
bound vs frame a frame is in the superviews coordinate system. A bound is in the views own coordinate system.
class or struct class is pass by reference, struct by value. Apple recommend using structs as the default.
Cocoa and Cocoa Touch the former is for OSX, the latter for iOS.
Concurrency in iOS delivered through threads, dispatch and operation queues. Concurrency is tasks running in overlapping time periods (time slicing) whereas parallelism is about performing work at the same time. Concurrency is in the same time space, parallelism at the same time.
Copy on write Swift only copies value types when they need to be changed, if not use the same instance of the value type.
Copy retain difference similar to pass by reference and value. Retain increases the retain count, whereas copy clones the object.
Delegate pattern this pattern is ubiquitous throughout the iOS APIs. Shifts responsibility from one class to another, creating a separation of responsibilities and concerns (avoid tight coupling). Gives a message to a single listener (the delegate).
Escaping closures can outlive the function, through use of the @escape keyword.
Extension or category categories and extensions allow you to functionality to an object without subclassing or changing the object. Extensions are not names (categories are). Categories can be used to add methods to pre existing classes (String, Float, etc.) whereas extensions allow us to add extra features to our custom class.
final prevents overrides.
Frameworks from UIKit to AFNetworking, RXSwift through Alamofire and Realm frameworks are incredibly important in the development of applications. CocoaPods is one dependency manager that helps you to use Frameworks in your project.
Grand Central Dispatch (GCD) abstracts threading through the concept of queues. Main queue, private queue are possible. Can choose concurrent queues and can dispatch using async or sync.
Any and AnyObject differences AnyObject is only for reference types (in particular classes), whereas Any can be used for anything.
loadView as a function, loadView() creates and instantiates the UIView object. Should not be called directly, is used to create views. Not used if using IB.
Method Swizzling change the functionality of a method at runtime. (actually a selector is an example if this). Hard to maintain. Can be used to swap out viewWillAppear to track every view, while keeping the original around. Google Analytics / Firebase is an example of this.
Memory leak a portion of memory that is occupied forever and never used again. This takes space and causes problems in the App.
Control transfer statements break, continue, fall through, return and throw.
Pass by value / Pass by reference structs, enums and tuples are value types, and each instance keeps a copy of its data. Classes are pass by reference, and instances share a single copy of data.
Pros of native over React Native having one codebase is preferable over multiple codebases for different platforms, making it faster and cheaper and even opens the door for web development. However, RN does not support all APIs. Equally to link into native components you need to use native code, fragmenting the codebase taking away the single largest benefit of using React Native.
protocol this lists required and optional methods that must be implemented from a class, struct or enum that adopts the protocol.
reuseIdentifier indicates that a cell can be reused in a UITableView, the UITableView maintains an internal cache of UITableViewCells.
unowned similar to weak, but not optional.
viewDidLoad, viewDidAppear viewDidLoad is called when the viewcontroller is loaded, viewDidAppear where the viewcontroller is visible.
weak or strong a strong reference means that only when the owning object is destroyed, the descendent object will only then be destroyed. A weak reference means that it can be destroyed when no other object has a strong reference to it.
When guard let, when if let guard is for incorrect inputs, if is for program flow. Therefore guard can make execution faster.
== or === == checks if values are the same, comparing value types. === compares reference types, seeing if they are identical which means that they are at the same memory address.
CollectionView vs TableView a tableview is a list of items in a single column, CollectionView is similar but has multiple rows and columns. You can actually configure a CollectionView to look much like a TableView, but there isn’t an immediately compelling reason for doing so beyond future extensibility.
Computed property does not store a value but retrieves and sets other properties and values indirectly.
Content hugging, compressions resistance content hugging cannot grow, compression resistance cannot shrink.
Downcasting as is used for upcasting, as? is used for safecasting and as! used to force cast.
Forced unwrapping when we have an optional, to use it we need to unwrap it. This means putting ! at the end, and we need to guarantee that the optional is not nil as if it is we will encounter a crash.
guard can avoid the pyramid of doom and provide early exits.
Initialization this is a way to prepare a struct, class or enum for use. Stored properties cannot be left in an indeterminate state, can have convenience and custom intializers or the default initializer.
inout inout passes by reference, a regular parameter passes by value.
Main thread where all UI work should be.
Nil coalescing operator if the left side of the ?? operator is nil then the value to the right of ?? is used
Optional binding the if let pattern
Optional chaining if any optional is nil, the entire chain fails gracefully
Stored property represented by the key words let or var, that is a constant (let) or a variable (var) as stored in a class or a structure.
SwiftUI a set of tools to build user interfaces.
Tenary Operator the tenary operator takes three arguments and returns a result depending on the first result of the three. array.isEmpty ? true : false would return true is the array is empty, and false if it is not.
Transition from not running an App moves from not running, briefly through inactive through the active (and possibly the background state) when launched.
Transition to being suspended an App moves briefly to background while being moved to the suspended. While in the background code can be run, but once moved to suspended no code is run.
UIKit used to develop the user interface for iOS, as an alternative to SwiftUI (predating the latter).
autorelease: decrements the receiver’s retain count.
Advantages of Swift optionals, error handling, closures, type safety, speed, ARC, dynamic library, pattern matching, playground and built using the Xcode IDE.
Class hierarchy for UIButton UIButton> UIControl> UIView> UIResponder> NSObject.
Closures or blocks closures captures variables that are mutable rather than copied. Objective-C blocks are compatible so closures can be passed to blocks.
Defer usage enables out of order statements, and can be used around opening and closing a context within a scope.
Faster iteration NSSet NSArray NSarray is comparatively faster since the access time is O(1), and NSSet is O(1) amortized.
KVC (Key-Value Coding) amechanism by which an objects properties can be accessed indirectly.
Stack or Heap we manage the memory on the heap. The stack is fast access, variables are stored and the stack cannot be resized. Heap can be access globally with slow access but no memory limit.
Type Annotation explicitly define the type using a colon:
Type Inference Swift can infer the type of anything you write.
Type Safety enforces good behaviour in that you cannot incorrectly mix types. Swift is a type safe language.
A Bit more challenging
Core Data Core Data is an object graph and persistence framework. Operates on data stored in memory, requires a save process and leaves data constraints to the business logic side of the program.
Extensions in Swift can add computed instance properties and computed properties, define instance methods, provide new initialisers, define subscripts, define new nested types and make an existing type conform to a protocol.
GCD or NSOperation GCD is low level, and is comparatively simple in the implementation of it’s API. NSOperation allows more granularity in it’s functions (cancelling, dependencies, observable).
How to create a screen that depends on two API calls in this case we could use Boolean variables, but that is relatively a poor solution. DispatchGroup is a class that enables you to manage a group of tasks as a single unit, and can therefore much better manage this type of process.
Another approach might be to use reactive programming, something like Combine or RxSwift (for the former this sounds like a good use for flatMap)
Implicitly assigned raw values when you use an enum to store integer or string raw values you do not have to assign a raw value for each case.
push or modal segue push pushes a view on the navigation stack. Modal presents on top of the current view controller.
Responder chain the responder chain is a series of linked responder objects. If the first responder cannot handle an event, it forwards it to the next responder in the chain.
typealias is a named alias of an existing type, so allow a new name to refer to an existing type.
Type Properties properties can be declared with the static keyword that apply to the type rather than an instance of that type.
unwind segue an unwind segue moves backwards through one or more segues to return the user to a scene managed by an existing view controller.
weak self and unowned self weak handles the case it might be nil without holding onto a strong link. Unowned does the same, but the variable cannot be nil.
Auto layout calculates the size and the position of all the views in the view hierarchy, based on constraints. The views can dynamically respond to both internal and external changes. External changes can be rotations, and internal changes can be changes in content. One power of using stack views is to leverage the power of Auto Layout without introducing the complexity of constraints. Autolayout equations are equality, not assignment and have to be resolved.
Pattern matching Tuples, type-casting, wildcards, option, enumeration case, expression.
Lazy stored property a property that is calculated only when the property is called the first time (can’t use with let, can’t use computed properties, must be a member of a struct or a class, and not thread safe).
Two phase initialization there are four safety checks that together prevent property values from being accessed before they are initialized, and prevents property values being set by another initializer unexpectedly.
Slightly longer topics
Explain Initializing with closures
If a stored property’s default value requires some customization or setup, you can use a closure or global function to provide a customized default value for that property. Whenever a new instance of the type that the property belongs to is initialized, the closure or function is called, and its return value is assigned as the property’s default value.
Define Capture list ?
If you want to capture the value of a variable at the point of the closure creation, instead of having it evaluate only when the closure executes, you can use a capture list.
Capture lists are written between square brackets right after the closure’s opening bracket (and before the closure’s arguments / return type if any)
To capture the value of a variable at the point of the closure’s creation (instead of a reference to the variable itself), you can use the
[localVar = varToCapture]capture list.
I’ve developed this list over a number of years. You know what, it’s really helped me out.
I really hope that it helps someone else out too — the job market requires that you have a certain competency in technical skills and this list can help you make that barrier.
What else is there? Well, I’ve created a series of artices that can help you out. You’re reading one of them now. Even better might be to hit me up on Twitter you want to ask me anything from the like: HERE.
In any case, good luck with your programming journey!