50 iOS Interview Questions And Answers Part 3

Updated on Jan, 2024
Hello, Part 3 is ready! Check out Part 1 and Part 2 if you haven’t already :)
1- Explain the Mediator Design Pattern
The mediator object encapsulates the interaction policies in a hidden and unconstraining way. Objects being manipulated by mediators have no idea it exists. It sits quietly behind the scenes and imposes its policies without their permission or knowledge.
If you want to learn more about this pattern, I recommend checking the Mediator Pattern Case Study.
2- Please explain “Arrange-Act-Assert”
AAA is a pattern for arranging and formatting code in Unit Tests. If we were to write XCTests each of our tests would group these functional sections, separated by blank lines:
- Arrange (Given) all necessary preconditions and inputs.
- Act (When) on the object or method under test.
- Assert (Then) that the expected results have occurred.
3- What is the benefit of writing tests in iOS apps?
- Writing tests first gives us a clear perspective on the API design, by getting into the mindset of being a client of the API before it exists.
- Good tests serve as great documentation of expected behavior.
- It gives us confidence to constantly refactor our code because we know that if we break anything our tests fail.
- If tests are hard to write its usually a sign architecture could be improved. Following RGR ( Red — Green — Refactor ) helps you make improvements early on.
4- Explain Unit Testing
Unit testing is a software testing technique where software applications are tested in isolation from the rest of the system. Unit tests are crucial for ensuring that code functions as expected, catching potential errors or regressions, and providing developers with confidence to make changes in the codebase.
5- What is RGR ( Red — Green — Refactor)?

In layman’s terms, Test Driven Development (TDD) is a software development practice that focuses on creating unit test cases. Red, Green and Refactor are stages of the TDD (Test Driven Development).
- Red: Write a small amount of test code usually no more than seven lines of code and watch it fail.
- Green: Write a small amount of production code. Again, usually no more than seven lines of code and make your test pass.
- Refactor: Tests are passing, you can make changes without worrying. Clean up your code. There are great workshop notes here.
6- Explain Swift asserts
If we need to check our code for some kind of condition, we can use asserts. The assertions are a neat debugging tool. Assertions are for checking errors for developers. There are five assertion functions int the Standart Swift library.
- assert() > With assert function I can check the required condition of my code even if it is working right.
- assertionFailure() > Give us a hint about our project optimizations. In debug, mode app will terminate, but in the release, mode app will not terminate. The behavior would be undefined.
- precondition() > This function is more than assert(). If condition is not met, the application will terminate.
- preconditionFailure() > fatal error.
- fatalError() > forces our application to crash. Execution will not continue after this function has been called.
According to Apple’s Swift documentation:
We use asserts to make sure an essential condition is satisfied before executing any further code.
7- Please explain types of notifications.
There are two types of notifications: Remote and Local. Remote notification requires a connection to a server. Local notifications don’t require a server connection. Local notifications happen on the device.
8- When is a good time for dependency injection in our projects?
There are a few guidelines that you can follow.
Rule 1. Is Testability important to us? If so, then it is essential to identify external dependencies within the class that you wish to test. Once dependencies can be injected we can easily replace real services with mock ones to make it easy to test.
Rules 2. Complex classes have complex dependencies, include application-level logic, or access external resources such as the disk or the network. Most of the classes in your application will be complex, including almost any controller object and most model objects. The easiest way to get started is to pick a complex class in your application and look for places where you initialize other complex objects within that class.
Rules 3. If an object is creating instances of other objects that are shared dependencies within other objects then it is a good candidate for a dependency injection.
9- What kind of order functions can we use on collection types?
We can user Higher-order functions (map, flatmap, compactMap, filter, reduce etc.)
Higher-order functions are functions that can be passed as an argument to other functions.
map(_:): Returns an array of results after transforming each element in the sequence using the provided closure.filter(_:): Returns an array of elements that according to the matching condition that we want.reduce(_:_:): Returns a single value by combining each element in the sequence using the provided closure.sorted(by:): Returns an array of the elements in the sequence sorted based on the provided closure predicate.flatMap(_:): Returns an array that flattens the resulting nested array.compactMap(_:): Returns an array of results that contained nil get discarded.
To see all methods available from Sequence, take a look at the Sequence docs.
10- Explain Hashable type
You might want to check Part 3 — Q19 before reading the answer.
If we make that type Hashable such as a struct or an enum, we can pass our own objects. Because in Swift, Enums are automatically hashable. This will give a unique identifier. I highly recommend watching WWDC 2019 Advances in UI Data Sources session.
11- What can breakpoint do?
- We can change the state of our app. p is another LLDB command to see a debug representation of the current object.
- We can use the po command in the console to print a debug description and see the current values.
- We can change the value to test our code, without having to compile and return your code.
- We can trigger the breakpoint in a certain condition or stop the execution only from the second time it is triggered.
12- Please explain the SOAP and REST Basics differences.
- Both of them help us access Web services.
- SOAP uses XML-Scheme while REST uses URI-scheme.
- REST is quite faster than SOAP.
- SOAP is definitely the heavyweight choice for Web service access. REST ( Representational State Transfer ) provides a lighter-weight alternative.
- SOAP is heavily used in financial services and payment gateways. REST is popular for web services like Twitter and YouTube.
13- What is the difference between the cocoa touch class and the normal swift class?
If we choose Swift File, the next screen will show you the file name and choose a save location. When we click “Create” from here, we simply get an empty(ish) Swift file with the name we picked. They do not provide different types of classes. They just provide different file templates.
14- What is the difference between Filter and Map Function?
Map, we pass in a function that returns a value for each element in an array. The return value of this function represents what an element becomes in our new array.
Filter, we pass in a function that returns either true or false for each element. If the function that we pass returns true for a given element, then the element is included in the final array.
15- What is CoreData ?
Core data is an object graph manager that also has the ability to persist object graphs to the persistent store on a disk. An object graph is like a map of all the different model objects in a typical model view controller iOS application. CoreData has also integration with Core Spotlight.
But Core Data is not thread safe, meaning that, if you load a managed object on one thread, you can’t pass it to another thread and use it safely. This becomes an issue when we want to start introducing threading for performance, so we have two choices.
The first is to keep everything on the main thread, which just means it’s single threaded. Or the second means making changes on background threads and passing managed object IDs and then loading those objects again on the main thread, but that would mean that you’re on the main thread, which puts us right back where we started. Both of these kind of ruin the point of using threading within Core Data and they can add a lot of complexity to the data layer.
There’s also another option for that and it’s to convert the managed object to a plain old Swift object, or a POSO.
16- Could you explain Associatedtype?
If you want to create a Generic Protocol we can use Associatedtype. For more details check this out.
17- Explain Bridging Headers in the iOS project
Bridging Headers allow us to include Objective-C files with our Swift files.
18- Explain Priority Inversion
When we send a task to a queue with a higher level than the QoS existing value of the queue, priority inversion occurs and the QoS value of the queue is increased to the value of the task. This new value applies to all tasks in the queue.
When the QoS value of the queue increases, we may cause low-priority tasks to get ahead of our important tasks because we perform the tasks we planned as a low priority with higher priority.
19- What is Hashable?
Hashable allows us to use our objects as keys in a dictionary. So we can make our custom types that can be compared for their equality using it’s hashValue
20- When do you use optional chaining vs. if let or guard?
We use optional chaining when we do not really care if the operation fails; otherwise, we use if let or guard. Optional chaining lets us run code only if our optional has a value.
Using the question mark operator like this is called optional chaining. Apple’s documentation explains it like this:
Optional chaining is a process for querying and calling properties, methods, and subscripts on an optional that might currently be nil. If the optional contains a value, the property, method, or subscript call succeeds; if the optional is nil, the property, method, or subscript call returns nil. Multiple queries can be chained together, and the entire chain fails gracefully if any link in the chain is nil.
21- How many different ways to pass data in Swift ?
There are many different ways such as Delegate, KVO, Segue, and NSNotification, Target-Action, Callbacks.
22- How do you follow up clean code for this project ?
I follow style guide and coding conventions for Swift projects of Github and SwiftLint.
23- Explain to using Class and Inheritance benefits
- With Overriding provides a mechanism for customization
- Reuse implementation
- Subclassing provides reuse interface
- Modularity
- Subclasses provide dynamic dispatch
24- What’s the difference optional between nil and .None?
There is no difference. Optional.None (.None for short) is the correct way of initializing an optional variable lacking a value, whereas nil is just syntactic sugar for .None. Check this out.
25- What is GraphQL ?
GraphQL is trying to solve creating a query interface for the clients at the application level. Apollo iOS is a strongly-typed, caching GraphQL client for iOS, written in Swift.
In practice, a GraphQL API is organized around three basic structures: schema, queries, and resolvers.
26- Explain Common features of Protocols & superclasses in Objective-C
- implementation reuse
- provide points for customization
- interface reuse
- supporting modular design via dynamic dispatch on reused interfaces
27- Explain Dynamic Var usage
I use KVO to trigger events on a case-by-case basis. Strong var variables cannot detect this trigger. This trigger can be detected when it puts dynamic at the beginning of the variable
28- What is the difference between Delegates and Callbacks?
If something requires only one function as its interface, a callback is usually a good solution. If more than one function is required, especially when they’re required for the basic function of an object, a Delegate is probably a better solution.
29- Explain Linked List
Linked List basically consist of the structures we named the Node. These nodes basically have two things. The first one is the one we want to keep. (we do not have to hold single data, we can keep as much information as we want), and the other is the address information of the other node.
Disadvantages of Linked Lists, at the beginning, there is extra space usage. Because the Linked List have an address information in addition to the existing information. This means more space usage.
30- What is the difference between setUp() and tearDown() in XCTestCase ?
We use these two methods for allocation. setUp method calls before test methods are executed. tearDown method calls after all test methods are executed for cleaning up any changes we made in data.
31- Explain AutoLayout
AutoLayout provides a flexible and powerful layout system that describes how views and UI controls calculate the size and position in the hierarchy.
Here are the key concepts and components of AutoLayout in iOS:
- Constraints define the relationship between different elements in a user interface.
- Interface Builder is a visual design tool integrated with Xcode, the official IDE for iOS development.
- The storyboard is a visual representation of the app’s user interface flow.
32- What is the disadvantage to hard-coding log statements ?
First, when you start to log. This starts to accumulate. It may not seem like a lot, but every minute adds up. By the end of a project, those stray minutes will equal to hours.
Second, Each time we add one to the code base, we take a risk of injecting new bugs into our code.
33- What is Pointer?
A pointer is a direct reference to a memory address. Whereas a variable acts as a transparent container for a value, pointers remove a layer of abstraction and let you see how that value is stored.
34- Explain Thread Sanitizer
Enabling Thread Sanitizer allows us to debug data races when multiple threads try to access the same memory area in a nonatomic way and with at least one write operation in one of those threads.
Thread Sanitizer is only supported for 64-bit macOS and 64-bit iOS and tvOS simulators. watchOS is not supported.
Thread Sanitizer | Apple Developer Documentation
35- Explain Autoclosures
@autoclosure creates an automatic closure around the expression. When we write an expression, @autoclosure is automatically wrapped into a closure
36- Explain blocks
Blocks are a way of defining a single task or unit of behavior without having to write an entire Objective-C class. they are anonymous functions.
37- What is the difference between try? and try! ?
try? allows us to ignore our error to become nil. We use try! it for our function to never encounter an error.
38- Explain the differences between static typing and dynamic typing
- Swift (Static Typing): Swift, the modern programming language for iOS development, is statically typed. Developers declare the types of variables explicitly, and type checking is done at compile time.
- Objective-C (Dynamic Typing): Objective-C, which has been traditionally used for iOS development, is dynamically-typed. Variables in Objective-C can hold different types of objects at runtime, providing more flexibility but potentially leading to runtime errors.
39- Explain the difference between atomic and nonatomic synthesized properties
atomic : It is the default behaviour. If an object is declared as atomic then it becomes thread-safe. Thread-safe means, at a time only one thread of a particular instance of that class can have the control over that object.
nonatomic: It is not thread-safe. We can use the nonatomic property attribute to specify that synthesized accessors simply set or return a value directly, with no guarantees about what happens if that same value is accessed simultaneously from different threads. For this reason, it’s faster to access a nonatomic property than an atomic one.
40- Why do we use availability attributes ?
Apple wants to support one system version back, meaning that we should support iOS16 or iOS15. Availability Attributes lets us to support previous version iOS.
41- How could we get device token ?
There are two steps to get device token. First, we must show the user’s permission screen, after we can register for remote notifications. If these steps go well, the system will provide device token. If we uninstall or reinstall the app, the device token would change.
42- What is Encapsulation ?
Encapsulation is an object-oriented design principles and hides the internal states and functionality of objects. That means objects keep their state information private.
43- What is big-o notation ?
An algorithm is an impression method used to determine the working time for an input N size. The big-o notation grade is expressed by the highest value. And the big-o notation is finding the answer with the question of O(n). Here is a cheat sheet and swift algorithm club. For example;
For Loops big-o notation is O(N). Because For Loops work n times.
Variables (var number:Int = 4) big-o notation is O(1).
44- What Is Dependency Management?
If we want to integrate open source project, add a framework from a third party project, or even reuse code across our own projects, dependency management helps us to manage these relationships. Check this out
45- Explain the difference between Category and Extension in Swift
Categories is an Objective-C term for extension in swift. Basically we can extend the closure outside of the class.
46- Explain throw
We are telling the compiler that it can throw errors by using the throws keyword. Before we can throw an error, we need to make a list of all the possible errors you want to throw.
47- What is Protocol Extensions?
We can adopt protocols using extensions as well as on the original type declaration. This allows you to add protocols to types you don’t necessarily own.
48- What is three triggers for a local notification ?
Location, Calendar, and Time Interval. A Location notification fires when the GPS on your phone is at a location or geographic region. Calendar trigger is based on calendar data broken into date components. Time Interval is a count of seconds until the timer goes off.
49- Explain Selectors in ObjC
Selectors are Objective-C’s internal representation of a method name.
50- What is Remote Notifications attacment’s limits ?
We can be sent with video or image with push notification. But maximum payload is 4kb. If we want to sent high quality attachment, we should use Notification Service Extension.
My recommendations
- A curated awesome list of iOS interview questions.
That’s it. 😃😃😃 Thanks for reading. I hope all these questions will help you in your interviews. Part 4 is ready.
If you want to follow me in social media, here are some links. github, twitter, instagram





