Popular Basic iOS Interview Questions Flashcards
Explain the Architecture of iOS.?
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
- 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.
- 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.
- 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. - 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.
What do you mean by property in iOS?
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.
What are the Classification of Properties in iOS?
Classification of Properties :
- 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.
- 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.
Can you explain the difference between atomic and non-atomic properties? What is the default for synthesized properties?
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.
What are different types of iOS Application States?
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:
- Not running: In the Not Running state, an application has either not been launched or has been closed/shut down by the system.
- 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.
- 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.
- 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.
- 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.
What do you mean by deep linking in iOS?
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.
Explain what is GCD (Grand Central Dispatch) in iOS.
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
What is ARC (Automatic Reference Counting)?
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 :-
- ARC creates a new class instance using init() and allocates a chunk of memory to store the information.
- 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(). - By tracking current referring classes’ properties, constants, and variables, ARC ensures that deinit() is only applied to those instances that are unused.
State the difference between Cocoa and Cocoa Touch.
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 :
- It is an application framework for building applications that run on Mac OS X.
- Frameworks such as Foundation and AppKit are incorporated into Cocoa.
- Cocoa classes use the NS (used for all classes and constants in the cocoa framework) prefix (like NSTextField, NSWindow).
Cocoa Touch :
- It is the application framework for building applications that run on devices like iPhones and iPad.
- Cocoa Touch is a combination of Frameworks such as Foundation and UIKit are incorporated into Cocoa Touch.
- 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).
What is the framework that is utilized to build an application’s interface for iOS?
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:
- Event handling (handle different gestures like input gestures, button-tap gestures, multi-touch gestures, etc.)
- App structure (Manages the interaction between the system and user)
- User Interface (Provides user interactions, the ability to share text and content, select images, edit videos, print files, etc.)
- Graphic, Drawing, and Printing
Write different ways to achieve concurrency in iOS?
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:
- 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.
- 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.
- 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.
State the difference between App ID and Bundle ID?
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.
What do you mean by the SpriteKit and SceneKit framework in the context of game development?
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.
Write the difference between assign and retain keywords.
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.