Popular Basic iOS Interview Questions Flashcards

1
Q

Explain the Architecture of iOS.?

A

iOS operates in a Layered structure. iOS Architecture is comprised of four layers, each of which offers a programming framework for creating applications that operate on top of the hardware. Communication will be enhanced by the layers between the Application Layer and the Hardware Layer. A lower-level layer provides the services that all applications require, while an upper-level layer (or high-level layer) provides graphics and interface-related services.

https://www.interviewbit.com/ios-interview-questions/#ios-architecture

  1. Core OS ( or Application) Layer:
    Core OS Layer sits directly on top of the device hardware and is the bottom layer of the iPhone OS stack.

In addition to basic operating system services, such as memory management, handling of file systems, and threads, this layer provides low-level networking, access to external accessories, etc.

  1. Service Layer:
    Its purpose is to design the services that upper layers or users demand.

Among its other essential features are block objects, Grand Central Dispatch, in-app purchases, and iCloud storage. The service layer has been strengthened by the addition of ARC Automatic Reference Counting.

  1. Media Layer:
    It handles media like video, audio, graphics, etc. The media layer will allow us to use all graphics, video, and audio technology of the system.
  2. Cocoa Touch Layer:
    It is also known as the application layer. This is the place where frameworks are created when applications are built.
    In addition, it functions as the interface for iOS users to work with the operating system. This includes touch and motion capabilities.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What do you mean by property in iOS?

A

Properties are basically values that are associated with a class, struct, or enum. They can be thought of as “sub-variables,” i.e., parts of another object.

struct Icecream
{
var flavor: String = “”
}
var choco = Icecream()
choco.flavor = “Chocolate Icecream”

In the above code, we created a structure called Icecream. One of its properties is called flavor, a String whose initial value is empty.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What are the Classification of Properties in iOS?

A

Classification of Properties :

  1. Stored Properties:

This type of property can be used to store constant or variable values as instances and is usually provided by classes and structures.

Example:

class Programmer {
var progName: String
let progLanguage: String
var totalExperience = 0
var secondLanguage: String?
}

Above, the Programmer class defines four stored properties: progName, progLanguage, totalExperience, and secondLanguage. These are all stored properties since they can contain values that are part of the instance of the class. The above example shows properties with and without default values, as well as an optional one.

  1. Computed properties:

These properties can be used to calculate values instead of storing them and are usually provided by classes, enumerations, and structures.

Example :

struct Angle {
var degrees: Double = 0

var rads: Double {
    get {
        return degrees * .pi / 180
    }
    set(newRads) {
        degrees = newRads * 180 / .pi
    }
} }

As mentioned above, the angle structure has a stored property called degrees for storing angles in degrees. Moreover, angles can also be expressed in radians, so the Angle structure contains a Rads property, which is a computed property.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Can you explain the difference between atomic and non-atomic properties? What is the default for synthesized properties?

A

It is the default property and ensures a valid value will be returned from the getter or set by the setter. This ensures that only one thread can access the getter/setter of a given property at a time and that all other threads must wait until the first thread releases the getter/setter. Despite being thread-safe, it is not fast, since it ensures that the process is completely completed.

With non-atomic properties, multiple threads can access the getter/setter method of a given property at the same time, so the potential for inconsistency between values exists. They come with enhanced access, but no guarantee of the return value.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What are different types of iOS Application States?

A

During the course of its execution, an iOS application goes through a series of states. Each of these states is referred to as an application’s lifecycle state. Below are the five possible states for an iOS app:

  1. Not running: In the Not Running state, an application has either not been launched or has been closed/shut down by the system.
  2. Inactive: A brief state of inactivity occurs while the app is leaving or entering its active state. Despite running in the foreground, it isn’t yet ready to accept user input or events. This means that the application remains inactive at this time.
  3. Active: The Active state indicates that the app is running in the foreground and receiving events. This is usually the normal mode for foreground apps and the User Interface is accessible.
  4. Background: During this state, the application’s user interface is hidden, but it continues to run in the background of the iOS system. Applications usually pass through this state prior to being suspended.
  5. Suspended: In this case, the application is in the background but is not running code. However, it stays in my memory. Under low memory conditions, the system can delete apps in the suspended state without warning.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What do you mean by deep linking in iOS?

A

Deep links are links that send users directly to an app directly instead of a website or store using URI (Uniform resource locator) or universal links.

The URL scheme is a well-known method of having deep links, but Universal Links are Apple’s new approach to connecting your web page and your app under the same link.

Deep linking involves not only creating a clickable link that opens up your app, but also a smart one that navigates to the resource you desire. Users are directed straight to in-app locations using these links, which saves them the time and effort of finding those pages themselves thus improving their user experience tremendously.

Explanation: If you use the URL fb://, you may open the Facebook app. However, if you use fb://profile/33138223345, you will open Wikipedia’s profile in the Facebook app.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Explain what is GCD (Grand Central Dispatch) in iOS.

A

Grand Central Dispatch (GCD) is a low-level API that enables users to run concurrent tasks (occurring simultaneously) by managing threads in the background.

Grand Central Dispatch is Apple’s solution to build concurrency and parallelism into iOS applications, so multiple background tasks can be run concurrently in the background without affecting the main thread. It was introduced in iOS 4 to avoid the tedious process of serial execution of tasks

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is ARC (Automatic Reference Counting)?

A

In the Swift programming language, automatic reference counting (ARC) is used to manage apps’ memory usage. It initializes and deinitializes system resources, thereby releasing memory reserved by a class instance when it no longer needs it.

ARC keeps track of how many properties, constants, and variables currently refer to each class instance. When there is at least one active reference to an instance, ARC will not deallocate that instance. The use of ARC concepts is an essential part of iOS development.

Functions of ARC :-

  1. ARC creates a new class instance using init() and allocates a chunk of memory to store the information.
  2. Memory stores information about the instance type and its values.
    As soon as the class instance is no longer required, ARC automatically frees memory by calling deinit().
  3. By tracking current referring classes’ properties, constants, and variables, ARC ensures that deinit() is only applied to those instances that are unused.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

State the difference between Cocoa and Cocoa Touch.

A

Cocoa and Cocoa Touch are two of Apple’s widely used application frameworks used for building applications. However, they differ in the following ways:

Cocoa :

  1. It is an application framework for building applications that run on Mac OS X.
  2. Frameworks such as Foundation and AppKit are incorporated into Cocoa.
  3. Cocoa classes use the NS (used for all classes and constants in the cocoa framework) prefix (like NSTextField, NSWindow).

Cocoa Touch :

  1. It is the application framework for building applications that run on devices like iPhones and iPad.
  2. Cocoa Touch is a combination of Frameworks such as Foundation and UIKit are incorporated into Cocoa Touch.
  3. Cocoa Touch classes, on the other hand, use the UI (used for all classes and constants in the cocoa touch framework) prefix (like UITextField and UIWindow).
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is the framework that is utilized to build an application’s interface for iOS?

A

Contrary to the Foundation framework that defines classes, protocols, and functions for both iOS and OS X development, UIKit is specifically designed for iOS development. In iOS, the user interface and graphical infrastructure of the application are developed using UIKit. It includes:

  1. Event handling (handle different gestures like input gestures, button-tap gestures, multi-touch gestures, etc.)
  2. App structure (Manages the interaction between the system and user)
  3. User Interface (Provides user interactions, the ability to share text and content, select images, edit videos, print files, etc.)
  4. Graphic, Drawing, and Printing
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Write different ways to achieve concurrency in iOS?

A

Concurrency means “running multiple tasks simultaneously”. Concurrency allows iOS devices to handle background tasks (such as downloading or processing data) while maintaining a responsive user interface.

In iOS, you can manage concurrent tasks using Grand Central Dispatch (or GCD), and Operations (formally known as NSOperation). In order to achieve concurrency, iOS provides three ways as follows:

  1. Dispatch queues:

They are used to manage tasks in first-in-first-out (FIFO) order and execute tasks sequentially or concurrently. This is an easy way to handle asynchronous (not occurring at the same time) and concurrent tasks in your application.

  1. Threads:

An independent sequence of instructions can be executed separately from other code within a program. Through threads, one can execute multiple code paths simultaneously in a single application. Having a thread is especially useful when you need to perform a lengthy task without affecting the execution of the rest of the program.

  1. Operation Queues:

Operation queue objects are invoked in accordance with their priority and readiness. Essentially, operation queues are high-level abstractions of queueing models, built on top of GCD (Grand Central Dispatch). It is possible, therefore, to execute tasks concurrently, just like GCD, but in an object-oriented manner.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

State the difference between App ID and Bundle ID?

A

Bundle ID:

They are the unique identifiers of applications in Apple’s ecosystem. In other words, no two applications can have the same identifier. The bundling ID is used for both OS X and iOS apps and can be used to recognize app updates.

Example:
If our organization’s domain is scaler.com and we create an app named Edge, you could assign the string com.scaler.edge as our app’s bundle ID.

App ID:

This string uniquely identifies one or more apps from the same development team. There are two components to the string, the Team ID and the Bundle ID, separated by a period (.). Apple supplies a Team ID to identify a specific development team, whereas developers supply Bundle IDs to identify a single app or a collection of apps.

Example:
ABCDE12345.com.scaler.edge
In the above example, ABCDE12345 is the Team ID and com.scaler.edge is the Bundle ID.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What do you mean by the SpriteKit and SceneKit framework in the context of game development?

A

SpriteKit: This framework is designed to make it easier and faster for game developers to create animated 2D assets/objects in casual games. With it, you can draw shapes, particles, text, images, and videos in two dimensions.

SceneKit: It is an iOS framework inherited from OS X, which helps to create 3D graphics. With SceneKit, you can build 3D animated scenes and effects for your iOS games and apps.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Write the difference between assign and retain keywords.

A

Assign:

With Assign, a reference is created from one object to another without increasing the source’s retain count (a number that keeps track of how many objects are “holding onto” another object). It does not copy or retain the value but assigns it directly to the instance variable.

Example:

if (object != object)
{
[object release];
object = nil;
object = object;
}

Here, Assign will generate a setter that assigns the value to the instance variable directly, rather than copying or retaining it.

Retain:

Using this method, you create a reference from one object to another and increase the retain count of the source object.

Example:

if (object != object)
{
[object release];
object = nil;
object = [object retain];
}

A retain message prevents an object from being deallocated until you are done using it.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly