Top iOS Fundamental Interview Questions and Answers

Keenan Warouw
DANA Product & Tech
15 min readAug 20, 2021

--

According to Backlinko, an estimated 1 billion people uses iPhone worldwide. With the addition of Apple TV and Apple Watch users, the market keeps on expanding, and iOS software engineers are in high demand.

The talent shortage keeps pushing salaries higher and higher, even for entry-level positions. Software development is also one of the few fortunate jobs that you can do remotely. It’s understandable then that more and more people are interested to become an iOS developer.

In this article, I will include common interview questions, how often they would come up, and how I personally would answer these questions.

I will rank the rarity by how often the questions come up during my interviews :
Rare (1–3 times out of 10)
Uncommon (4–6 times out of 10)
Common ( 7–9 times out of 10)
Every Time! (10 times out of 10)

After reading this article, hopefully, you can land that iOS Developer job that you wanted. I will also include a way to greatly boost your chance of succeeding in your interview at the end of this article 😉

Basic Object-Oriented Programming

1. What is the relation between class and object?

  • Class is a template of an object, which defines properties and behaviors. And an object is an instance of a class. ex:
  • Class MainViewController: UIViewController {} ← Class Declaration
  • let vc: UIViewController = UIViewController() ← Object Definition

Rarity: Uncommon
Notes: While this question doesn’t appear as frequent, it will give a bad impression if you can’t answer this question as it is a very basic question.

2. Please explain the 4 Pillars of OOP

  • Abstraction.
    Abstraction is an OOP concept by which we expose relevant data and methods of an object while hiding their internal implementation.
  • Encapsulation.
    Encapsulation is a concept by which we hide data and methods from outside intervention and usage.
  • Inheritance.
    Inheritance is defined as a process by which a child class inherits the properties of the parent class.
  • Polymorphism.
    Objects of the same class can behave independently within the same interface.

read more about the 4 pillars in detail here: https://medium.com/swift-india/oops-in-swift-998738407423

Rarity: Rare
Notes: For mid-senior level positions, this question doesn’t come out as often as it is a question designed for entry-level positions and people with less experience with iOS Development. However, the 4 pillars expand to any Software Development role and not just iOS.

3. Please explain the difference between Struct and Class

  • Struct is a value type while Class is a reference type.
  • A reference type passes an object by its memory address while a value type passes the value.
  • Classes can also be inherited while Structs cannot. Both can conform to protocols in Swift.

Rarity: Every time!
Notes: This question came out in every single interview I’ve had regardless of the seniority level. A must-know for iOS Developers.

4. Overriding Method vs Overloading Method

  • Method overloading is the process by which a class has two or more methods with the same name but different parameters.
  • Overriding is the process by which two methods have the same method name and parameters. One of the methods is in the parent class and the other is in the child class. An example is how we override viewDidLoad() method in our ViewController class.

Rarity: Rare
Notes: Same as the 4 pillars, a fundamental question that expands to more than iOS Development role.

Design Patterns

1. Please explain the MVC(Model-View-Controller) pattern, what are its pros and cons?

  • M- Model, the Model Layer in MVC should hold and represent your application data.
  • V- View, the View Layer in MVC should handle your application’s interface logic and controls the objects that your users can interact with. Basically, all the UIView derived objects.
  • C- Controller, the Controller layer in MVC is the mediator between the View and the Model. It accesses the Data in the Model and will adjust the View accordingly.
  • Pros- MVC is the most common and used design pattern in the iOS environment. It is easy to learn, people can adapt to it easily, and most iOS developers are familiar with it.
  • Cons- The Controller holds too much responsibility in this pattern. There are jokes within the community that MVC stands for Massive-View-Controllers because of how convoluted the Controller classes are in this pattern.

Rarity: Every time!
Notes: You absolutely have to know what MVC is since it’s essential to any iOS development. There are other common architectures like MVVM, VIPER, and MVP that you can explore, but MVC will be the one on the top of the list for iOS Development. If you are asked about a Design Pattern that you have no prior experience of, it’s better to say so rather than trying to explain something that you read from the internet but have no experience of.

2. Explain the Singleton pattern. What are its pros and cons?

  • The Singleton design pattern ensures that only a single instance exists for a given class and that there’s a global access point to that instance. An example would be when you use instances like UserDefaults.standard or DispatchQueue.main
  • Pros- It can be accessed everywhere, therefore easy to access no matter the class you are trying to use it from.
  • Cons- Since it can be accessed everywhere, it can easily be abused by the developers and it might be hard to trace where the data are being manipulated if it is being modified in too many places.

Rarity: Common
Notes: One of the most used patterns and the one most prone to being misused. How you explain this pattern will determine your seniority level.

3. Explain the Observer pattern. What are its pros and cons?

  • In the Observer design pattern, an observed object called the Observable will broadcast all its changes to any objects that observe it(Observers). An example of an Observer pattern in iOS would be the NotificationCenter.
  • Pros- Very handy to use since you can run a method when you detect changes.
  • Cons- Might find it hard to track the flow if there are too many observers observing the same observable.

Rarity: Common
Notes: There are more design patterns in iOS, like Facade, Adapter, Decorator, etc. The Singleton and Observer are the most frequently asked ones in my experience. Again, if you are asked about a Design Pattern that you have no prior experience of, it’s better to say so rather than trying to explain something that you read from the internet but have no experience of.

Views and Interface Builder

1. What is the difference between frames and bounds?

  • The view’s frame is its location and size according to its parent’s coordinate system
  • A view’s bounds are its location and size according to its own coordinate system
  • Example you create a view at x:0 y: 0, with width: 50 height:50. When you move the view’s coordinate, the view’s frame will reflect the change but its bounds will not.
  • The same thing will happen when you try to rotate the view. The view’s frame will reflect the change, while the bounds will not. Because internally in the view, it hasn’t changed
  • example code:

Rarity: Common
Notes: Another frequently asked question. You can easily get them mixed up between each other so be sure to try them out beforehand!

2. Name the inheritance tree of a UIButton

NSObject — UIResponder — UIView — UIControl — UIButton

credit: https://stackoverflow.com/questions/3323209/class-hierarchy-of-nsobject

Rarity: Rare
Notes: Although specifically asking the inheritance tree of a UIButton is rare, interviewers like to ask about classes and the behaviors that it inherits from the parent.

3. Explain how you will create this interface in your app

There are many ways to create this, using storyboard, programmatically, xibs, etc. Just explain your most comfortable way of creating. Explain how you can place everything in the middle of the screen, probably by using the superview’s center, width, and height. Explain how you can place the writing relative to the image, and how the bottom label’s placement is relative to its top label. Don’t forget to mention autolayout if you are using it.

Rarity: Uncommon
Notes: Keep in mind that this is a sample image. The interviewer can come up with any kind of layouts they want and will try to understand your problem-solving skills on how to create a specific layout.

4. What is the difference between UICollectionView and UITableView? When to use which?

  • UICollectionView enables you to scroll horizontally and vertically. While UITableView only allows vertical scrolling
  • UICollectionView has UICollectionViewDelegateFlowLayout which provides you the ability to control the flow
  • UICollectionView allows the user to dynamically change the size and shapes of each cell
  • UICollectionView also supports custom animations in different types of layouts

Rarity: Common
Notes: One of the most instrumental tools in creating a layout in iOS. Interviewers will be looking at your experience with each tool.

Application Lifecycle

This article by @pleelaprasad brilliantly explained the iOS Application Lifecycle. I will try to summarize it for interview questions here

1. What are the iOS Application states? Briefly explain them.

  • Not Running/Terminated- The state when the application has not started or has been terminated
  • Inactive- The state when the application is running in the foreground, but is not receiving any events. The most common way to achieve this state is when you receive a call when using the app. This state could also be achieved during the transition between other states. App UI cannot be interacted while in this state
  • Active- The normal state for a foreground app. The app is running in the foreground and is receiving events. This is the state when the user is using the app and is interacting with the app.
  • Background- The application is running in the background and can still execute codes. When you minimize the app, it transitions to this state briefly, usually about 5 seconds, before transitioning to the suspended state.
  • Suspended- The application is in the background and is not executing any codes. This state is achieved automatically by the system and does not notify. When the system detects low memory on the device, it may purge applications that are in the suspended state without notifying them.

Rarity: Common
Notes: Although perfectly answering all states are good, missing a few things make you human. Certain states are used more frequently than other and certain apps might not even touch a specific state. Answer according to your experience.

2. What happens when the user swipes up or presses the home button to minimize the app?

The application that is in the foreground will transition from Active state to Inactive state briefly. The app will then be in a Background state and process any final event it needs to. After a few seconds, the app will be put in the Suspended state. If the system needs more memory for the current foreground app, the suspended app may be Terminated

Rarity: Common
Notes: Not much to say about this. A frequently asked question and a pretty straightforward answer

Memory Management

1. How is memory management handled on iOS?

In Swift, there is something called ARC(Automatic Reference Counting) that tracks and manages memory usage. It is similar to Garbage Collector in Java if you have experience with it. ARC automatically frees up the memory used by class instances when those instances are no longer needed.

Rarity: Every time!
Notes: Another must know! Memory management is very important in any application, especially in iOS apps that have memory and other hardware and system constraints. Memory leaks and app crashes are all too common due to poorly managed memory in iOS apps.

2. What is a strong and weak reference?

  • Strong- when you declare a strong reference to an object, you are telling ARC not to deallocate the object when there are still references to the object. This also increases the retain count by 1
  • Weak- A weak reference is a reference that doesn’t keep a strong hold on the instance it refers to, and so doesn’t stop ARC from disposing of the referenced instance. ARC will change a weak reference to nil when it is being deallocated. Because of that, a weak reference cannot be a constant(let) and must be a variable(var)

Rarity: Every time!
Notes: As mentioned before, memory management is very important in iOS Development so this question will come naturally as a follow-up question from before. In Objective-C, in addition to weak and strong, there’re also types like assign and retain.

3. What is a retain cycle and how do you solve it?

  • A retain cycle happens when at least 2 objects hold a strong reference to each other. Therefore preventing ARC to deallocate the object, preventing the retain count to be 0, and preventing the memory to be freed.
  • To solve it, you need to decrease the retain count to 0. One way to do this is by making the strong references to be a weak reference.

Rarity: Every time!
Notes: There are other approaches on how to solve a retain cycle and that is a field that you can deep dive to learn on. Making a strong reference into weak is just the most common alternative

Thread Management

1. What are the different threads in iOS?

From high to low priority with an explanation on when to use:

https://developer.apple.com/documentation/dispatch/dispatchqos

Rarity: Uncommon
Notes: Although it’s not common that interviewers ask you to name all of the QoS, it is essential to know that there are different threads in iOS and at the very least you should be able to name the main thread and the background thread.

2. What is a Serial and Concurrent queue?

From Apple developer docs:

  • Serial queues (also known as private dispatch queues) execute one task at a time in the order in which they are added to the queue. The currently executing task runs on a distinct thread (which can vary from task to task) that is managed by the dispatch queue. Serial queues are often used to synchronize access to a specific resource.
  • Concurrent queues (also known as a type of global dispatch queue) execute one or more tasks concurrently, but tasks are still started in the order in which they were added to the queue. The currently executing tasks run on distinct threads that are managed by the dispatch queue. The exact number of tasks executing at any given point is variable and depends on system conditions.

Rarity: Uncommon
Notes: This question can be word differently, or asked in a different way. They can ask about synchronous and asynchronous tasks instead.

3. What is a Race Condition?

A race condition occurs when two or more tasks are executed concurrently when they should be executed sequentially in order. You can’t change the view constraint while it is being calculated. So UI activity should be done in the main thread so it is executed sequentially.

Rarity: Rare
Notes: While not being a commonly asked question, this question can boost the impression of your interviewers if you can answer it with experience.

Storage

1. What are the persistence data options available in iOS and when to use which?

  • UserDefaults- UserDefaults is easy to use. It can be accessed throughout the app, it can collide keys though as it uses the keys to store values. Data inside UserDefaults is not encrypted.
  • CoreData- CoreData enables you to save customized Data objects. Not very simple to use and needs to learn before fully mastering it. Need to also look out for the thread-safety.
  • FileManager- FileManager saves data using URL paths. It can be used with iCloud, it can also save large objects like photos. URL paths can be error-prone. The reading/saving process can be slow.
  • Keychain- The main advantage of using Keychain is that the data are encrypted for security. Although speed can be slower and is not recommended for large objects. Useful for saving sensitive data like emails, phone numbers, etc.
  • plist- plist is easy to use, it stores some app values. It can only store small objects or data types though.

Rarity: Common
Notes: Most of the time, they won’t expect you to name all the options, just the one you have experience with. Or they can specifically ask how UserDefaults or Keychain work and not give a care to the rest. Knowing about UserDefaults is essential though as it is the most common persistence data used in iOS.

Other Common Questions

1. Why do we use dequeueReusableCellWithIdentifier in table views and collection views?

By using dequeueReusableCell, we only create the cells needed to fill the screen and a little more. As the user scrolls, this method will dequeue the cells that are no longer on the screen and reuse them for new cells. Leading to a much more memory-efficient task.

Rarity: Uncommon
Notes: 99% of the time, if you have created a TableView or CollectionView before, you have used the function dequeueReusableCellWithIdentifier. It will leave a positive impression for the interviewers if you can explain the tools that you have used and not only copying online sources.

2. What is Reactive Programming?

Reactive Programming focuses on asynchronous data streams, which you can listen to and react accordingly. In simple form, reactive programming enables you to subscribe and react to changes within an object, rather than requiring you to re-check object states and manually adding conditions

Rarity: Common
Notes: For a large-scale project, Reactive Programming is extremely useful. If you’re joining an established team of developers with a large-scale product, they will ask this question most of the time.

Practice Questions

Below are practice questions for you that I have used to interview people and have received during interviews.

  1. How do you debug memory leaks? (zombie, memory debugger, etc)
  2. What do you use to integrate dependencies into your project? (Cocoapods, Carthage, SPM, etc)
  3. How do you test your project? (Unit Test and UI Tests, what framework you use)
  4. How do you run a background fetch? (how you update the app while it is not active to reduce the amount of updates that needed to be downloaded when the user opens the app)
  5. How do you handle push notifications?
  6. What is the difference between static and dynamic library?
  7. What are the View Lifecycle processes and what do they do? (viewDidLoad, viewDidAppear, viewDidDisappear, etc.)

Conclusion and What’s Next

Thank you for reading this article. Again, this article compiles the question that I have received and used for interviews. You might have a completely different experience during interviews and receive different questions compared to mine. I would be happy to hear your interview stories in the comments!

Hopefully, after reading this article, you can word your interview answers better and understand the things that you have been using, but could not quite find the right words to describe them.

The best way to succeed in the job interview that you are aiming for from my experience is by trying out a few interviews beforehand. I read an article suggesting people try interviews every 2 years even if you are content with your current workplace. Not only does an interview helps you present yourself, helps you get updated with the current trend, review the things you have done, it also enables you to know the current situation and demand in your industry.

Every time you fail an interview, you can note the questions that you fail to answer, learn about them afterward, and answer them on the next interview. So it is a good practice to ask a friend to do a mock interview with you, or do a real interview for practice and get better each time. For me, it is a challenging and rewarding experience. You don’t have to accept the job offer if you don’t feel like it.

Thank you for reading my article! Big kudos to my mentors, mas Yoga and mas Heru for their feedbacks and for helping me polish this article. If you have any questions or have anything to add, feel free to comment them below or reach out to me at Linkedin. Any inputs or feedbacks are welcome!

Sources:
https://backlinko.com/iphone-users

https://iosinterviewguide.com/ios-interview-questions-for-senior-developers-in-2020

https://docs.swift.org/swift-book/LanguageGuide/AutomaticReferenceCounting.html

--

--