Top Answers to iOS Interview Questions

1. What are the characteristics of iOS?
CriteriaResult
Type of operating systemApple proprietary based on Macintosh OS X
OS fragmentationTightly integrated with Apple devices
SecurityHeightened security guaranteed
2. Which JSON framework is supported by iOS (iPhone OS)?
  • SBJson framework is supported by iOS. 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.
3. How can you prevent iOS 8 app's streaming video media from being captured by QuickTime Player on Yosemite during screen recording?

HTTP live streams that have their media encrypted will not be recorded by QuickTime Player on Yosemite while screen recording. These will blackout in the recording.
HTTP live streaming: It sends live and on‐demand audio and video to iPhone, iPad, Mac, Apple TV, and PC with HTTP live streaming (HLS) technology from Apple. Using the same protocol that powers the web, HLS lets us deploy the content using ordinary web servers and content delivery networks. HLS is designed for reliability and dynamically adapts to network conditions by optimizing playback for the available speed of wired and wireless connections.

CTA

Check out this video on iOS Development Tutorial:

Top iOS Interview Questions and Answers

Learn for free ! Subscribe to our youtube Channel.

4. Name the framework that is used to construct the application’s user interface for iOS.
  • The UIKit framework is used to develop 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
5. 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
6. 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.
CTA

7. What is the difference between retain and assign?

Assign creates a reference from one object to another without increasing the source’s retain count.

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

Retain creates a reference from one object to another and increases the retain count of the source object.

if (_variable != object)
{
  [_variable release];
    _variable = nil;  
_variable = [object retain];  
}
8. 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 an 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.

To learn more about the layout of elements, check out this iOS Tutorial!

9. What is the difference between atomic- and non-atomic properties? Which is default for synthesized properties? When would you use one over the other?

Properties specified as atomic are guaranteed to always return a fully initialized object. This also happens to be the default state for synthesized properties. While it is a good practice to specify atomic properties to remove the potential for confusion, if we leave it off, the properties will still be atomic.

This guarantee of atomic properties comes at the cost of performance. However, if we have a property for which we know that retrieving an uninitialized value is not a risk (e.g., if all access to the property is already synchronized via other means), then setting it to non-atomic can boost the performance.

10. Describe managed object context and its function.

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.
11. Explain a singleton class.

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;
}
12. What is an unnamed category?

An unnamed category has fallen out of favor now that @protocol has been extended to support the @optional methods.

Class Extensions

@interface Foo() is designed to allow us to declare additional private API— system programming interface (SPI)—that is used to implement the class innards. This typically appears at the top of the .m file. Any methods/properties declared in the class extension must be implemented 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
13. Does Objective-C contain private methods?

No, there is nothing called a private method in Object-C programming. If a method is defined in .m only, then it becomes protected; if it is defined in .h, it is public.

If we really want a private method, then we need to add a local category/unnamed category/class extension in the class and add the method in the category and define it in class.m.

14. What is a plist?

Property list or plist refers to a list that organizes data into named values and lists of values using several object types. These types provide us the means to produce data that is meaningfully structured, transportable, storable, and accessible, but still as efficient as possible. Property lists are frequently used by applications running on both Mac OS X and iOS. The property-list programming interfaces for Cocoa and Core Foundation allow us to convert hierarchically structured combinations of these basic types of objects to and from standard XML. We can save the XML data to the disk and later use it to reconstruct the original objects.

The user defaults system, which we programmatically access through the NSUserDefaults class, uses property lists to store objects representing user preferences. This limitation would seem to exclude many kinds of objects, such as NSColor and NSFont objects, from the user defaults system. However, if objects conform to the NSCoding protocol, they can be archived to NSData objects, which are property-list-compatible objects.

Click here to learn more about iOS in the iOS Development Training!

15. What is the purpose of reuseIdentifier? What is the benefit of setting it into a non-nil value?

The reuseIdentifier is used to group together the similar rows in a UITableView, i.e., the rows that differ only in their content, otherwise having similar layouts. A UITableView will normally allocate just enough UITableViewCell objects to display the content visible in the table.

If reuseIdentifier is set to a non-nil value, then the UITableView will first attempt to reuse an already allocated UITableViewCell with the same reuseIdentifier when the table view is scrolled. If reuseIdentifier has not been set, then the UITableView will be forced to allocate new UITableViewCell objects for each new item that scrolls into view, potentially leading to laggy animations.

16. What is the difference between an ‘App ID’ and a ‘Bundle ID’? What is each used for?
    • An App ID is a two-part string used to identify one or more apps from a single development team. The string consists of a Team ID and a Bundle ID search strings, with a period (.) separating the two.
    • The Team ID is supplied by Apple and is unique to a specific development team, while a Bundle ID is supplied by the developer to match either the Bundle ID of a single app or a set of Bundle IDs of a group of apps.

Since most users consider the App ID as a string, they think it is interchangeable with the Bundle ID. Once the App ID is created in the Member Center, we can only use the App ID prefix that matches the Bundle ID of the application bundle.

The Bundle ID uniquely defines each app. It is specified in Xcode. A single Xcode project can have multiple targets and, therefore, outputs multiple apps. A common use case: an app having both lite/free and pro/full versions or branded multiple ways.

CTA

17. What is an abstract class in Cocoa?

Cocoa doesn’t provide anything called abstract. It can create a class abstract that gets checked only at the runtime while it is not checked at the compile time.

@interface AbstractClass : NSObject
@end
@implementation AbstractClass
+ (id)alloc{
    if (self == [AbstractClass class]) {
        NSLog(@"Abstract Class can’t be used");
    }
    return [super alloc];
@end
18. What is NSURLConnection class? Define its types and use cases.

There are two ways of using the NSURLConnection class. One is asynchronous and the other is synchronous.

An asynchronous connection will create a new thread and perform its download process on the new thread. A synchronous connection will block the calling thread while downloading the content and doing its communication.

Many developers think that a synchronous connection blocks only the main thread, which is not true. A synchronous connection will always block the thread from which it is fired. If we fire a synchronous connection from the main thread, the main thread will be blocked. However, if we fire a synchronous connection from a thread other than the main thread, it will be like an asynchronous connection and won’t block our main thread.

In fact, the only difference between synchronous and asynchronous connections is that at the runtime a thread will be created for the asynchronous connection while it won’t do the same for a synchronous connection.

In order to create an asynchronous connection, we need to:

  1. Have our URL in an instance of NSString
  2. Convert our string to an instance of NSURL
  3. Place our URL in a URL Request of type NSURLRequest or, in the case of mutable URLs, in an instance of NSMutableURLRequest
  4. Create an instance of NSURLConnection and pass the URL request to it

If you have any doubts or queries related to iOS, get them clarified from iOS experts on our iOS Community!

19. What is the relation between iVar and @property?

iVar is an instance variable. It cannot be accessed unless we create accessors, which are generated by @property. iVar and its counterpart @property can be of different names.

@interface Box : NSObject{
    NSString *boxName;
}
@property (strong) NSString *boxDescription;//this will become another ivar
-(void)aMethod;
@end
@implementation Box
@synthesize boxDescription=boxName;//now boxDescription is accessor for name
-(void)aMethod {
    NSLog(@"name=%@", boxName);
     NSLog(@"boxDescription=%@",self.boxDescription);
    NSLog(@"boxDescription=%@",boxDescription); //throw an error
}
@end

13 thoughts on “Top iOS Interview Questions and Answers”

Leave a Reply

Your email address will not be published. Required fields are marked *

Interview Questions

p get_sidebar('iq'); ?>