iOS Interview Questions Part 1

Saeid Rezaeisadrabadi
4 min readAug 12, 2024

--

In this post, I want to write 10 iOS interview questions you might face, providing insights and strategies to help you ace your next interview.
Preparing for an iOS interview can be both exciting and nerve-wracking. With the mobile app industry booming, landing a job as an iOS developer can open up incredible opportunities. However, the interview process often comes with its own set of challenges. From coding tasks to system design questions, understanding what to expect can give you a significant edge. Whether you’re a senior developer or just starting out, this guide will help you navigate the key topics that interviewers are likely to focus on, so you can confidently walk into your interview.

Question 1

Consider the following code snippet:

protocol HasArea {
var area: Double { get }
}
class Circle: HasArea {
let pi = 3.1415927
var radius: Double
var area: Double { return pi * radius * radius }
init(radius: Double) { self.radius = radius }
}
class Country: HasArea {
var area: Double
init(area: Double) { self.area = area }
}
class Animal {
var legs: Int
init(legs: Int) { self.legs = legs }
}

You initialize an array named objects that contains instances of all three types. How can you iterate through it, checking which items conform to the HasArea protocol?

Answer 1

for object in objects {
if let objectWithArea = object as? HasArea {
print("Area is \(objectWithArea.area)")
} else {
print("This item does not have an area")
}
}

Question 2

Which feature of Xcode allows you to launch your application in a device simulator so that Xcode can capture your interaction with the app and generate user interface test code?

Answer 2

The Record UI Test feature.

Question 3

You must create a file descriptor function in Swift. You write your first attempt:

func processFile(filename: String) throws {
if exists(filename) {
let file = open(filename)
while let line = try file.readline() {
// Work with the file.
}
close(file)
}
}

The open() function does not have a corresponding call to the close() function if the try statement file.readline() throws an error. How can you solve this problem?

Answer 3

Enclose the close() function in a defer statement and move it above the try statement.

Question 4

You suspect that a view controller is causing a retain cycle. How can you detect whether the system releases the view controller reference or not?

Answer 4

Create a Symbolic Breakpoint in the Breakpoint Navigator that Xcode calls when the system deallocates view controllers.

Question 5

In Swift, what occurs when you call an asynchronous method?

Answer 5

The code stops running until that method returns.

Question 6

What can you use to create a dynamic list of views in SwiftUI?

Answer 6

ForEach

Question 7

How would you check to see if a user already granted permission for your application to display notifications?

Answer 7

Call the notification center’s getNotificationSettings(completionHandler:) method and use the authorizationStatus property of the UNNotificationSettings instance that the system passes to the completion handler.

Question 8

What changes must you apply to the following SwiftUI view to add a search bar that filters the results of the colors array?

struct ContentView: View {
let colors = ["Red", "Green", "Yellow", "Blue"]

var body: some View {
NavigationView {
List {
ForEach(colors, id: \.self) { color in
NavigationLink(destination: Text(color)) {
Text(color)
}
}
}
.navigationTitle("Colors")
}
}
}

Answer 8

Add a searchable modifier to the List, an @State property to bind to the search, and a computed property that filters the colors array to loop over it in the ForEach.

Question 9

You must define a collection of test methods for your application. Before Xcode runs each test method, you want to run code that prepares a starting state for each test to use. How can you do this?

Answer 9

Implement a new class that inherits from XCTestCase and override the setUpWithError() method with the code that should run before each test method.

Question 10

You are designing a user interface that should display a UILabel with a larger font size on an iPad in landscape orientation compared to an iPhone in portrait orientation. How would you do this using size classes in your storyboard?

Answer 10

Create a variation for the UILabel's font size based on the Regular Width and Regular Height size class combination.

As you prepare for your iOS interview, remember that the key to success is not just knowing the right answers but also understanding the concepts behind them. By familiarizing yourself with the common questions we’ve covered and practicing your problem-solving skills, you’ll be better equipped to tackle any challenge that comes your way. Interviews are as much about demonstrating your thought process and communication skills as they are about technical knowledge. So, take a deep breath, stay calm, and showcase the passion and expertise that make you a standout iOS developer. Good luck, and may your next interview lead to exciting new opportunities in your career!

--

--

Saeid Rezaeisadrabadi
Saeid Rezaeisadrabadi

Written by Saeid Rezaeisadrabadi

Over 8 years of experience in iOS software development

No responses yet