IOS Interview Question And Answers


On June 29, 2007, the world got the first iOS software phone from Apple, the iPhone, released by Steve jobs. It is a fantastic device operating platform that lets Apple users interact with their devices using gestures, like tapping, swiping, and pinching. The most striking fact about it is that iOS software goes through some minor updating every year by adding new features to tweak and improve the user experience.

To excel at iOS interview questions, you should at least know the basic facts of iOS. The iOS app developer must create the software using Objective-C or Swift programming language. You must also know that to build apps for iOS software, you must use the iOS software development kit (SDK). Moreover, there is reviewing of the application before the launch.

Facts

You must have noticed that almost every Apple device includes ‘i’ in the product name, such as the iPhone, iPad, iCloud, and iTunes. So, where did it come from? The original iMac was the first Apple product whose name starts with an ‘i’. Steve Jobs gave his speech with the tagline, “The excitement of the internet. The simplicity of Macintosh.”

IOS includes strict APIs and governance of apps which help Apple devices in terms of security. Moreover, it consists of a bunch of default Apple apps, and Apple produces their software, such as Safari, a web browser and Apple Music, an audio streaming app. However, you must know that all Apple devices do not use iOS. Apple products such as Mac desktops and laptops have MacOS operating systems.

Some vital features you must know for your iOS interview questions are as below:

  • Multitasking: iOS software provides incredible multitasking support via the following seven Background APIs.
  • Interface: iOS software users get a smooth experience of multi-touch gestures like swipe, tap, pinch, etc., to interact with the applications. Also, users get internal accelerometers which help devices to respond to the shaking of the device or rotate in 3D.
  • Apple pay: Apple pay is the most valuable and exciting feature of the iOS software by which a user can make payments safely. The application is invulnerable and uses FaceID and TouchID to operate.
  • Home screen: An operator can quickly launch the applications as the iOS device’s home screen contains the widget and app icons.
  • Location services: If you permit the device, it can use the location services to give access to your device location.

1 . Which JSON framework is that iOS (iPhone OS) supports?

  • The iOS supports SBJson framework. It is a JSON parser and generator for Objective-C (Objective-C is the primary programming language we use when writing software for OS X and iOS. It is a superset of the C programming language and provides object-oriented capabilities and a dynamic runtime).
  • SBJson provides flexible APIs and additional control that makes JSON handling easy.

2 . What is an unnamed category in iOS?

An unnamed category has fallen out of favor now that @protocol extends to support the @optional methods. Class Extensions @interface Foo() allow us to declare an additional private API— system programming interface (SPI)—that implements the class innards. This typically appears at the top of the .m file. Any methods/properties that you declare in the class extension must implement in the @implementation, just like the methods/properties found in the public @interface. Class extensions can also be used to re-declare a publicly read-only @property as read-write prior to doing @synthesize on the accessors.

Example:

Foo.h
@interface Foo:NSObject
@property(readonly, copy) NSString *bar;
-(void) publicSaucing;
@end
Foo.m
@interface Foo()
@property(readwrite, copy) NSString *bar;
- (void) superSecretInternalSaucing;
@end
@implementation Foo
@synthesize bar;
.... must implement the two methods or compiler will warn ....
@end

3 . Name the framework that constructs the application’s user interface for iOS.

  • The UIKit framework develops the application’s user interface. The UIKit framework provides event handling, drawing model, windows, views, and controls, specifically designed for a touch-screen interface.
  • The UIKit framework (UIKit.framework) provides the crucial infrastructure needed to construct and manage iOS apps. This framework provides:
    • Window and view architecture to manage an app’s user interface
    • Event handling infrastructure to respond to the user input
    • An app model to drive the main run loop and interact with the system

In addition to the core app behaviors, UIKit provides support for the following features:

  • A view controller model to encapsulate the contents of the user interface
  • Support for handling touch and motion-based events
  • Support for a document model that includes iCloud integration
  • Graphics and windowing support, including support for external displays
  • Support for managing the app’s foreground and background execution
  • Printing support
  • Support for customizing the appearance of standard UIKit controls
  • Support for text and web content
  • Cut, copy, and paste support
  • Support for animating user-interface content
  • Integration with other apps on the system through URL schemes and framework interfaces
  • Accessibility support for disabled users
  • Support for the Apple Push Notification service
  • Local notification scheduling and delivery
  • PDF creation
  • Support for using custom input views that behave like the system keyboard
  • Support for creating custom text views that interact with the system keyboard
  • Support for sharing content through Email, Twitter, Facebook, and other services

4 . Which is the application thread from where UIKit classes should we use?

Use UIKit classes only from your application’s main thread or main dispatch queue. This restriction applies in particular to classes derived from UIResponder or that require modifying the user interface of your app in some way.

5 . What is the difference between Synchronous & Asynchronous tasks in iOS?

Synchronous can also be defined as In order. When you perform the synchronous operation, all that follows must wait for the operation to complete before proceeding.

In contrast, “asynchronous” can also be defined as “out of order.” When you do something asynchronously, you can run the following code right away, and the asynchronous process will happen someday. You can also run on a separate thread from the rest of the code. It could easily be rescheduled on the same thread at a later date and you can notify you when it is done.

6 . How can you respond to state transitions on your app?

State transitions can be responded to state changes in an appropriate way by calling corresponding methods on the app’s delegate object.

For example:

  • applicationDidBecomeActive( ) method: To prepare to run as the foreground app
  • applicationDidEnterBackground( ) method: To execute some code when the app is running in the background that may be suspended at any time
  • applicationWillEnterForeground( ) method: To execute some code when the app is moving out of the background
  • applicationWillTerminate( ) method: Called when the app is being terminated

7 . What is Operator Overloading?

The process of adding new operators and changing existing ones to do various things is known as operator overloading.

+, *, and / symbols are known as operators.

 8 . What is TVMLKit?

TVMLKit serves as a bridge between TVML, JavaScript, and your native tvOS software. You can test TVMLKit JS and TVML files from inside your tvOS app using the TVMLKit framework. The JavaScript environment can be used to build TVML objects, styles, views, and view controllers.

9 . What are UI Elements in iOS?

The visual elements that we can see in our applications are known as UI elements. Some of these components, such as buttons and text fields, respond to user interactions, while others, such as images and labels, provide information.

10 . What is Swift and what is Objective-C?

Swift is a modern programming language created by Apple for iOS, OS X, watchOS, and tvOS apps that combines the best of C and Objective-C, but without the C compatibility issues. Also, swift follows secure programming patterns while also incorporating modern features to make programming simpler, more versatile, and enjoyable. Swift is welcoming to novice programmers and feels familiar with Objective-C developers.

The primary programming language for writing applications for OS X and iOS is Objective-C. It’s an object-oriented programming language with a dynamic runtime that’s a superset of the C programming language. Objective-C takes C’s syntax, primitive types, and flow control statements and adds class and process definition syntax.

11 . What is an NSError in Swift?

The NSError class is a Cocoa class. The knowledge about an error condition is encapsulated in an extendable, object-oriented manner by an NSError object. It includes a predefined error domain, a domain-specific error code, and a user details dictionary with application-specific data.

12 . What are the features added in iOS 9?

The following features are added in iOS 9:

  • Intelligent search: It is an excellent mechanism to learn user habits and act on that information—open apps before we need them, make recommendations on places we might like, and guide us through our daily lives to make sure we’re where we need to be at the right time.
  • Siri: It is a personal assistant to the users that is able to create contextual reminders and search through photos and videos in new ways. Swiping right from the home screen brings up a new screen that houses ‘Siri Suggestions,’ putting favorite contacts and apps right on our fingertips, along with nearby restaurant and location information and important news.
  • Deeper search capabilities: It can show results such as sports scores, videos, and content from third-party apps, and we can even do simple conversions and calculations using the search tools on our iPhone or iPad.
  • Performance improvements: The following built-in apps have been improved:
    • Notes including new checklists and sketching features
    • Maps now offering transit directions
    • Mail allowing for file attachments
    • New ‘News’ app that learns our interests and delivers relevant content we might like to read
    • Apple Pay being improved with the addition of store credit cards and loyalty cards
    • ‘Passbook’ being renamed to ‘Wallet’ in iOS 9
  • San Francisco font
  • Wireless CarPlay support
  • Optional iCloud Drive app: It is a built-in two-factor authentication system with optional longer passwords for better security.

13 . What is the difference between KVC and KVO?

KVC (Key-Value Coding) is a method for accessing an object’s properties using strings at runtime rather than needing to know the property names statically at development time.

KVO (Key-Value Observing) allows a controller or class to monitor changes in a property value. In KVO, an object may request to be informed of any adjustments to a particular property, and the observer is automatically notified if that property’s value changes.

14 . Explain the different types of iOS Application States.

You will experience a few app states while using the application. There are five states in the ios application as follows.

  • Not Running

The application is in the Not running state, if the app is not launched yet or if the application is not visible on the screen or also there is the possibility that the application is terminated by the user or by OS.

  • Inactive

An inactive state occurs when the application is not receiving events but the app is running in the background. An app transitions to a different state. when the user locks the screen or the system prompts the user to respond to some event such as a phone call or SMS message is the only time it stays inactive.

  • Active

In an ios application, Active State is the main executive state. In this state, the app is running in the foreground and the UI is accessible.

  • Background

Before being suspended most of all apps enter this state.  If an app requests extra execution time then that will remain in this state for some more time. Also, an application will be launched directly into the background enters this background state instead of the inactive state

  • Suspended

In a suspended state the application does not execute any code. The system purges suspended apps without any notice to make more space for the foreground app when a low-memory condition occurs.

15 . What is Dynamic Dispatch in iOS?

At runtime, Dynamic Dispatch determines which implementation of a polymorphic procedure, such as a method or a function, to call. This means that when we want to call our methods, such as object methods, we must use this syntax. Swift, on the other hand, does not use dynamic dispatch by default.

16 . What are the advantages of the Realm framework?

  • To handle all of the work, only a small amount of code is needed.
  • Available in both Object C and Swift.
  • SQLite and Core Data have slower performance.
  • Database files can be shared easily between iOS and Android devices.
  • There is no fee, no charge.
  • There is no limit to the data amount that can be stored.
  • Regardless of huge data sets or massive storage, consistent speed and consistency

17 . What are the different ways to specify the layout of elements in UIView?

Here are a few common ways to specify the layout of elements in UIView:

  • Using InterfaceBuilder, we can add a XIB file to our project, layout elements within it, and then load XIB in our application code (either automatically, based on naming conventions, or manually). Also, using InterfaceBuilder, we can create a storyboard for our application.
  • We can write our own code to use NSLayoutConstraints and have elements in a view arranged by Auto Layout.
  • We can create CGRects describing the exact coordinates for each element and pass them to UIView’s (id)initWithFrame:(CGRect)frame method.

18 . What is SpriteKit and what is SceneKit?

SpriteKit is a platform for creating animated 2D objects quickly and easily.

SceneKit is a platform for 3D graphics rendering that was inherited from OS X.

SpriteKit, SceneKit, and Metal are expected to boost a new generation of mobile games that push the boundaries of what the powerful GPUs in iOS devices can do.

19 . Explain a singleton class in iOS.

When only one instance of a class is created in the application, that class is called a singleton class. See below:

@interface SomeManager : NSObject
+ (id)singleton;
@end
@implementation SomeManager
+ (id)singleton {
static id sharedMyManager = nil;
@synchronized([MyObject class]){
if (sharedMyManager == nil) {
sharedMyManager = [[self alloc] init];
}
}
return sharedMyManager;
}
@end
//using block
+ (id) singleton {
static SomeManager *sharedMyManager = nil;
static dispatch_once_t  onceToken;
dispatch_once(&onceToken, ^{
sharedMyManager = [[self alloc] init];
});
return sharedMyManager;
}

20 . Differentiate between a frame and a bound?

A UIView’s bounds are a rectangle with a size (width, height) and position (x,y) relative to its own coordinate system (0,0).

A UIView’s frame is a rectangle with a scale (width, height) and position (x,y) relative to the superview it is located within.

21 . How to Prioritize Usability in Design?

To prioritize usability, the design process has broken down into 4 steps:

  • Consider the user’s perspective when designing the user experience.
  • Users, not demographics, are what you should focus on.
  • Consider all of the scenarios in which an app might be useful when promoting it.
  • Even after the app has been released, continue to improve its functionality.

22 . Explain iBeacons in iOS?

Apple’s introduction of Bluetooth low-energy (BLE) wireless technology, iBeacon, is a new way for iPhones and other iOS users to receive location-based information and services.

23 . Describe managed object context and its function in iOS.

A managed object context (represented by an instance of NSManagedObjectContext) is a temporary ‘scratchpad’ in an application for a (presumably) related collection of objects. These objects collectively represent an internally consistent view of one or more persistent stores.

A single-managed object instance exists in one and only one context, but multiple copies of an object can exist in different contexts.

The key functions of the managed object context include the following:

  • Life-cycle management: Here, the context provides validation, inverse relationship handling, and undo/redo.
  • Notifications: It refers to context posts’ notifications at various points that can be optionally monitored elsewhere in our application.
  • Concurrency: Here, the Core Data uses thread (or serialized queue) confinement to protect managed objects and managed object contexts.

24 . Why is the design pattern very important?

Design patterns are important in software design because design patterns are reusable solutions to many common problems. They’re models for writing code that’s simple to comprehend and reuse. The most popular design trends in Cocoa are as follows:

  • Creational: Singleton.
  • Structural: Decorator, Adapter, Facade.
  • Behavioral: Observer, and, Memento

25 . What is Concurrency?

Concurrency is a fancy term for “running several tasks at the same time.” On iOS devices, concurrency is commonly used to allow you to run tasks such as downloading or processing data in the background while keeping your user interface sensitive.

26 . Mention various ways to achieve concurrency in iOS?

Mainly, there are 3 ways to achieve concurrency in iOS. There are:

  • Grand Central Dispatch
  • OperationQueue
  • Threads

27 . What is meant by deadlock?

A deadlock is a situation that occurs when at least two threads are locked on a different resource, and both are waiting for the other resource to finish its job. And no one is able to unlock the resource it is guarding.

28 . Explain the lazy property in Swift?

A lazy stored property is one that does not determine its initial value until it is used for the first time. The lazy modifier is written before the declaration of a lazy stored property.

29 . What is ‘assign’ in iOS?

In iOS, ‘assign’ is used to create an orientation from one object to the other without raising the retain count of the source object.

30 . Why is ‘reuseIdentifier’ used?

The ‘reuseIdentifier’ is used to group all the similar rows from UITableView.

31 . How can you reduce the size of the App?

The three different methods to reduce app size are:

  1. Bit code
  2. On-demand Resource
  3. App Slicing

32 . What is the difference between retaining and copying?

Retaining an object means increasing the retain count by one. The instance of the object is kept in memory till its retain count drops to zero. A reference to the instance is stored, and the same is shared with anyone who retained it. At the same time, copy means that the object will be cloned with a duplicated value, but it cannot be shared with anyone else.

33 . What do you understand by category? When is it used?

A category is a way to add additional methods to a class without extending it. It is used to add a collection of related methods and additional methods to built-in classes in the Cocoa Frameworks. 

34 . Out of viewDidLoad and viewDidAppear, which should be used to load data from a remote server to display in the view?

It is dependent on the data’s use case. If data is static and is not likely to change, it can be loaded in viewDidLoad and cached. Whereas, if data changes regularly, use viewDidAppear to load it.

35 . What is a protocol, and how to define it?

Like an interface in Java, the protocol defines a list of optional and required methods that a class can/must implement to adopt the protocol. Any class can define a protocol, and other classes can send protocol method-based messages to the class without knowing its type.

36 . What is MVC? Tell me about its implementation in iOS. 

MVC or Model View Controller is a design pattern that defines how logic will be separated when the user interface is implemented. In iOS, UIView is the base class provided by Apple for all views, and UIViewController is provided to support the Controller, which listens to events in a View and updates it when data changes.

37 . What do you understand about dynamic dispatch?

The process of selecting which implementation of a polymorphic operation to call at run time is called Dynamic dispatch. It is used when we need to invoke our methods like the object method. 

38 . What is a Responder chain?

A ResponderChain is a hierarchy of objects that have the chance of responding to the received events.

39 . Give a brief about the singleton pattern.

The Singleton pattern is a design pattern that ensures only one instance exists for a given class and that instance has a global access point. When needed for the first time, it generally uses lazy loading to create a single instance. 

40 . List the benefits of Realm.

The benefits are as follows:

  1. Zero copy object store
  2. Open source database framework
  3. Fast
  4. Implemented from Scratch

41 . What is meant by the ‘defer’ keyword?

The ‘defer’ keyword provides a block of code executed in cases when execution leaves the current scope. 

42 . What is Model-View-ViewModel Architecture?

MVVM (Model View View-Model) is an iOS architectural design pattern in which we separate objects into three main components.

  • Model: It contains the application data. It is responsible for data parsing and data persistence.
  • View: It is responsible for displaying the model data on the screen, including the visual elements and controls. It is the subclass of UIView and highly reusable.
  • ViewModel: It contains the business logic that transforms the model data into the values and passes it to the view. In MVVM, all the business logic, including data manipulation, takes place at ViewModel.

43 . What is Model-View-Presenter Architecture?

Model View Presenter (MVP) is a design pattern that separates the objects into three main components: Model, View, and Presenter. Now, the View Controller is considered as View, and the presenter contains all the business logic of the application.

  1. View: The view consists of the View and View Controller. It contains only the view related code. It takes care of all the UI setup and events.
  2. Presenter: The presenter contains all the business logic of the application. It defines the user actions and updates the UI accordingly via the delegate methods. It is not UIKit dependent and, therefore, easily testable.
  3. Model: The model contains the application data. The networking calls, parser, extensions, manager, etc. take place here.

44 . What are the different types of Queues available for GCD?

There are three types of a queue available for GCD.

  1. Main Queue: the main queue runs on the main thread, and it performs the serial execution of the thread.
  2. Global Queue: The Global queue is a concurrent queue and shared by the whole system. There are four global queues that operate on different priorities. The priorities are high, default, low, and background, where the background priority queue holds the minimum priority.
  3. Custom Queue: the developer creates the custom queues. They can be either concurrent or serial.

45 . How to save data in UserDefaults?

To save the data in the UserDefaults, first, we need to get the reference to the UserDefaults by using the standard property.

UserDefaults.standard
 

The following code can be used to save a string in the UserDefaults.

let token = "ABCDEFGD!@#$456MK"    
UserDefaults.standard.set(token, forKey: "userToken")  

46 . How to remove data from UserDefaults?

To remove any value from the UserDefaults, the removeObject() method is used. Here, we want to remove the value for key userToken, we can write the following code.

UserDefaults.standard.removeObject(forKey : "userToken ") 

47 . How to add Pull-to-Refresh functionality in an iOS app?

Apple provides us the UIRefreshControl class, which simplifies adding the pull to refresh. The First thing we need to do is instantiate the UIRefreshControl class.

let refreshControl = UIRefreshControl()

Here, we need to add this refresh control to our view. We can assign the refreshControl property of the view to this instance. However, we must notice that, before iOS 10, there was not a property like refreshControl. We had to add it as a sub view to the view.

if #available(iOS 10.0, *) {    
    tableView.refreshControl = refreshControl    
}     
else {    
    tableView.addSubview(refreshControl)    
}