Interview questions for junior iOS developers

Omer Keskin
5 min readMay 19, 2024

--

Hello, I will discuss 7 questions and their answers that you may frequently encounter in recruitment interviews as a junior iOS developer, in this article.

What is a protocol in Swift and how is it used?

In Swift, a protocol outlines the properties, methods, and other specifications needed for a certain task or piece of functionality. Protocols can be adopted by classes, structs, and enums to give concrete implementations of these specifications. Protocols are used to achieve polymorphism, making code more flexible and reusable. For instance:

protocol Drivable {
func drive()
}

class Car: Drivable {
func drive() {
print("Driving a car")
}
}

let myCar = Car()
myCar.drive() // Output: Driving a car

What is the difference between “frame” and “bounds” in a UIView?

Frame: The frame of a UIView is its position and size relative to its superview’s coordinate system. It is defined by a CGRect containing the origin (x, y) and the size (width, height).

Bounds: The bounds of a UIView is its position and size relative to its own coordinate system. The origin is usually (0,0) unless you modify it for specific purposes like scrolling.

let view = UIView(frame: CGRect(x: 50, y: 50, width: 100, height: 100))

print(view.frame) // Output: (50.0, 50.0, 100.0, 100.0)
print(view.bounds) // Output: (0.0, 0.0, 100.0, 100.0)

How the memory is managed in iOS?

Automatic Reference Counting (ARC) is mostly responsible for managing memory on iOS devices. By monitoring the references to instances and deallocating them as necessary, ARC automatically maintains the memory of the instances. Key concepts include:

Strong References: By default, references are strong, meaning the instance is kept in memory as long as there is a strong reference to it.

Weak References: Declared with “weak” keyword, these references do not keep the instance in memory. Used to avoid retain cycles, especially in delegate patterns.

Unowned References: Similar to weak but used when the reference is expected to always have a value during its lifetime.

What is “Shadowing” in Swift?

The process of defining a variable, constant, or parameter within a scope that has the same name as an existing variable, constant, or parameter is known as “shadowing” in Swift. In the new scope, this “shadows” the original entity and prevents access to it. Shadowing can happen in a lot of different places, like functions, loops, and nested scopes.

Example : Shadowing in Functions

let value = 10

func printValue() {
let value = 20 // This value shadows the global value
print(value) // Output: 20
}

printValue()
print(value) // Output: 10

What is “Overloading” in Swift?

The ability to specify numerous functions, methods, or operators with the same name but differing parameter counts or types is known as overloading in Swift. This makes the code more accessible and intuitive by enabling you to use the same name for many uses.

Function Overloading: When you define several functions with the same name but distinct parameters, it’s known as function overloading. The arguments supplied to the function are used by the Swift compiler to decide which function to call.

func printValue(value: Int) {
print("Integer value: \(value)")
}

func printValue(value: String) {
print("String value: \(value)")
}

printValue(value: 10) // Output: Integer value: 10
printValue(value: "Hello") // Output: String value: Hello

Method Overloading: Method overloading, like function overloading, enables you to specify numerous identically named methods with distinct argument lists inside the same class or struct.

class Calculator {
func multiply(a: Int, b: Int) -> Int {
return a * b
}

func multiply(a: Double, b: Double) -> Double {
return a * b
}
}

let calculator = Calculator()
print(calculator.multiply(a: 3, b: 4)) // Output: 12
print(calculator.multiply(a: 3.5, b: 4.2)) // Output: 14.7

What is “Optional Binding” in Swift?

In Swift, optional binding provides a secure method of unwrapping an optional value — that is, gaining access to the value enclosed in an optional, if it is present. When binding optionally, the “if let” and “guard let” constructs are frequently used. These constructs allocate the value of an optional to a new variable or constant after determining whether it contains a value.

“if let” binding: If an optional variable has a value, you can use the if let construct to conditionally tie its value to a constant or variable. The condition fails and the function inside the if block is not run if the optional is nil.

var optionalName: String? = "Sebastian Vettel"

if let name = optionalName {
print("The name is \(name).") // Output: The name is Sebastian Vettel.
} else {
print("The optional was nil.")
}

In this example, “optionalName is an optional string. Using “if let, we check if it contains a value. If it does, the value is assigned to “name and printed. If “optionalName were “nil, the “else block would execute.

“guard let” binding: If the optional has no value, the guard let construct is used to end the current scope. It is frequently used in loops and functions to make sure specific requirements are satisfied before running the remaining code.

func greet(person: String?) {
guard let name = person else {
print("No name provided.")
return
}
print("Hello, \(name)!")
}

greet(person: "Charles") // Output: Hello, Charles!
greet(person: nil) // Output: No name provided.

In this example, the “guard let statement checks if “person contains a value. If “person is “nil, the “else block is executed, printing a message and exiting the function. If “person has a value, it is assigned to “name and the function proceeds to print the greeting.

What is MVVM?

A design pattern called MVVM (Model-View-ViewModel) is used in software development, especially for user interface (UI) applications, to better organize code, separate concerns, and increase testability. To clearly distinguish between the data (Model), the UI (View), and the logic that connects the data to the UI (ViewModel), Swift’s MVVM is frequently utilized in iOS development.

Components of MVVM

Model: Includes the logic and data structures needed to manage the data. Represents the application’s data and business logic. Usually communicates with databases, network services, or other data sources.

View: Represents the UI of the application, displays data from the ViewModel and handles user interactions.

ViewModel: Acts as an intermediary between the Model and the View. Exposes data and commands to the View, transforming the Model data into a format suitable for the View. Handles user input and updates the Model accordingly. Utilizes data binding to automatically update the View when the data changes.

I hope you find this article useful for your recruitment interviews and you can consolidate your knowledge. Best of luck for your career path…

--

--