Part 4— iOS Interview Preparation Questions and Explanations

Yasir
4 min readOct 22, 2020

100 + Que/Ans Series , I am posting a continue series on iOS Interview questions from a basic concept to advance . 😎

22. When would you say that an app is in active state ?

An app is said to be in active state when it is accepting events and running in the foreground.

23. What is the difference between Viewdidload and Viewdidappear ?

  • Viewdidload is called when it is loaded into memory .
  • Viewdidappear is called when the view is visible and presented on the device .

24. What do you meant by Concurrency ?

Concurrency is a condition in a program where two or more tasks are defined independently, and each can execute independent of the other, even if the other is also executing at the same time.

25. Which are the ways of achieving concurrency in iOS ?

The three ways to achieve concurrency in iOS are:

  • Threads
  • Dispatch queues
  • Operation queues

26. What is Thread ?

According to Apple:

“Threads are especially useful when you need to perform a lengthy task, but don’t want it to block the execution of the rest of the application. In particular, you can use threads to avoid blocking the main thread of the application, which handles user interface and event-related actions. Threads can also be used to divide a large job into several smaller jobs, which can lead to performance increases on multi-core computers.”

27. What is Dispatch Queue in Basics ?

According to Apple:

An object that manages the execution of tasks serially or concurrently on your app’s main thread or on a background thread.

28. Difference between Foreground and Background ?

The foreground contains the applications the user is working on, and the background contains the applications that are behind the scenes .

29. Classes

Classes are reference types, as opposed to value types . You create a class like :

class Person {
var firstName: String
var lastName: String
init(firstName: String, lastName: String) {
self.firstName = firstName
self.lastName = lastName
}

var fullName: String {
return "\(firstName) \(lastName)"
}
}
let john = Person(firstName: "Johnny", lastName: "Appleseed")

In Swift, an instance of a structure is an immutable value whereas an instance of a class is a mutable object. Classes are reference types, so a variable of a class type doesn’t store an actual instance — it stores a reference to a location in memory that stores the instance .

Here Comes Stack vs Heap !

When you create a reference type such as class, the system stores the actual instance in a region of memory known as the heap, while instances of a value type such as a struct resides in a region of memory called the stack .

  • The system uses the stack to store anything on the immediate thread of execution; it is tightly managed and optimized by the CPU. When a function creates a variable, the stack stores that variable and then destroys it when the function exits. Since the stack is so strictly organized, it’s very efficient, and thus quite fast.
  • The system uses the heap to store instances of reference types. The heap is generally a large pool of memory from which the system can request and dynamically allocate blocks of memory. Lifetime is flexible and dynamic. The heap doesn’t automatically destroy its data like the stack does; additional work is required to do that. This makes creating and removing data on the heap a slower process, compared to on the stack.

Working with Reference

var homeOwner = john 
john.firstName = "John"
john.firstName // "John"
homeOwner.firstName // "John"

Sharing among class instances results in a new way of thinking when passing things around. For instance, if the john object changes, then anything holding a reference to john will automatically see the update. If you were using a structure, you would have to update each copy individually, or it would still have the old value of “Johnny”.

Identity Operators

Because classes are reference types, it’s possible for multiple constants and variables to refer to the same single instance of a class behind the scenes.

In Swift, the === operator lets you check if the identity of one object is equal to the identity of another:

john === homeOwner // truelet newInstance = Person(firstName: "Johnny",  lastName: "Appleseed")newInstance === John // false

30. What is MVC ?

MVC stands for Model View Controller. Models represent application data; views draw things on the screen; controllers manage data flow between model and view. Model and view never communicate with each other directly and rely on a controller to coordinate the communication.

Where to go from here ?

Be updated of the series I am uploading , check this link . Or You can join this whatsapp group link.

My LinkedIn Profile : linkedin.com/in/my-pro-file

--

--

Yasir

Exploring the Swift, SwiftUI, and Apple universe.