TOP iOS Interview Questions and Answers
What is iPhone reference library?
iPhone reference library is a set of reference documents for iPhone OS.
It can be downloaded by subscribing to the iPhone OS Library doc set.
Select Help>Documentation from X code, and click the subscribe button next to the iPhone OS Library doc set, which appears in the left column.
When to use NSMutableArray and when to use NSArray?
Normally we use mutable version of array where data in the array will change. For example, you are passing a array to function and that function will add some elements to that array or will remove some elements from array, then you will select NSMutableArray. When you don’t want to change you data, then you store it into NSArray. For example, the country names you will put into NSArray so that no one can accidentally modify it.
Does iOS support multitasking?
iOS 4 and above supports multi-tasking and allows apps to remain in the background until they are launched again or until they are terminated.
Types of parsers?
There are various parsers available to parse an XML in iOS app development. You can choose either from iOS SDK provided by Apple or from third party libraries. Before discussing about various options, I want to highlight difference between XML parsers. Generally two types of parsers are used in XML parsing: SAX and DOM. Let’s have a look at their brief description.
SAX parser- This parser is based on some notifying methods. These methods are notified as the SAX parser moves on the XML document. During the parsing activity, developer is responsible to construct required object and keep track of state of the XML parser. Some examples of this parser are as follows-
NSXMLParser – It is written in Objective-C and provided by Apple through its iOS SDK.
libxml2 – It is based on C language API and also provided by Apple through its iOS SDK. It supports both SAX and DOM parser.
DOM parser- This parser parse the complete document in a single go and converts it into a specific structured object. We can create XPath query for a particular element from this structured object. Some examples of this parser are as follows-
TBXML- It’s a lightweight XML parser designed in such a way to consume very low memory. It’s a good choice for an XML as well as that have the fixed structure.
TouchXML – It is another DOM parser. It is also read only but does not support XPath queries.
KissXML – It is based on TouchXML parser. It supports editing and writing XML unlike TouchXML parser.
TinyXML – It is very small DOM parser and based on C language API. It supports editing and writing XML documents like KissXML parser but does not support XPath queries.
GDataXML – It is developed by Google using Objective-C API. It supports both editing of XML documents and XPath queries.
What is @dynamic and any place where it is used?
It tells compiler that getter and setter are not implemented by the class but by some other class.
May be super class or child class.
Example – Core Data.
– The Managed object classes have properties defined by using @dynamic.
What is iPhone sdk?
iPhone SDK is available with tools and interfaces needed for developing, installing and running custom native applications. Native applications are built using the iPhone OS’s system frameworks and Objective-C language and run directly on iPhone OS. Native applications are installed physically on a device and can run in presence or absence of network connection.
Where can you test Apple iPhone apps if you don’t have the device?
iOS Simulator can be used to test mobile applications. Xcode tool that comes along with iOS SDK includes Xcode IDE as well as the iOS Simulator. Xcode also includes all required tools and frameworks for building iOS apps. However, it is strongly recommended to test the app on the real device before publishing it.
Explain about the applications that can be used with iPhone?
Technology, Entertainment and Design (TED): Allows to watch and listen to world’s most fascinating people have to say, all on the iPhone.
What are KVO and KVC?
KVC: Normally instance variables are accessed through properties or accessors but KVC gives another way to access variables in form of strings. In this way your class acts like a dictionary and your property name for example “age” becomes key and value that property holds becomes value for that key. For example, you have employee class with name property.
You access property like
NSString age = emp.age;
setting property value.
emp.age = @”20?;
Now how KVC works is like this
[emp setValue:@”25? forKey:@”age”];
KVO : The mechanism through which objects are notified when there is change in any of property is called KVO.
For example, person object is interested in getting notification when accountBalance property is changed in BankAccount object.To achieve this, Person Object must register as an observer of the BankAccount’s accountBalance property by sending an
What is @implementation?
It’s a keyword used to define the Class.
What is iPhone?
Which API is used to write test scripts that help in exercising the application’s user interface elements?
Flow of push notification?
Your web server sends message (device token + payload) to Apple push notification service (APNS) , then APNS routes this message to device whose device token specified in notification.
What are layer objects and what do they represent?
Layer objects are data objects which represent visual content. Layer objects are used by views to render their content. Custom layer objects can also be added to the interface to implement complex animations and other types of sophisticated visual effects.
What is @interface?
It’s a keyword used to declare the Class.
What is MVC ? MVC Architecture of iPhone App.
Here are the reasons why we should use the MVC (Model View Controller)design pattern.
1. MVC is resuable: When the problems occurs, there is no need to invent a new solution, we just have to follow the pattern and adopt it as necessary.
2. MVC is expressive: By using the MVC design pattern our application becomes more expressive.
1). Model: The model object knows about all the data that need to be displayed. It is model who is aware about all the operations that can be applied to transform that object. It only represents the data of an application. The model represents enterprise data and the business rules that govern access to and updates of this data. Model is not aware about the presentation data and how that data will be displayed to the browser.
2). View: The view represents the presentation of the application. The view object refers to the model. It uses the query methods of the model to obtain the contents and renders it. The view is not dependent on the application logic. It remains same if there is any modification in the business logic. In other words, we can say that it is the responsibility of the of the view’s to maintain the consistency in its presentation when the model changes.
3). Controller: Whenever the user sends a request for something then it always go through the controller. The controller is responsible for intercepting the requests from view and passes it to the model for the appropriate action. After the action has been taken on the data, the controller is responsible for directing the appropriate view to the user. In GUIs, the views and the controllers often work very closely together.
Which app specific objects store the app’s content?
Data model objects are app specific objects and store app’s content. Apps can also use document objects to manage some or all of their data model objects.
Garbage collector in iPhone?
iOS has got the ARC ( Automated reference counting ). Objective C does not have a garbage collector rather it uses the reference counting algorithm to manage the memory. This was the developers task until Apple launched iOS 5.0. Again if you are targeting iOS 4.0 or earlier , ARC is no more a choice for you.
What are sensors in iPhone?
The proximity sensor immediately turns off the display when the iPhone is lifted to ear. With this sensor the power is saved and accidental dialing is prevented.
The display is automatically brightens the iPhone by the ambient light sensor when the sunlight or bright rooms and dims in darker places.
What is @synthesize?
We use @synthesize to generate getters and setters automatically from compiler. We declare properties and then generate getter and setter method by using @synthesize.
What is nonatomic?
nonatomic and atomic are related to multithreading environment . If a property has an attribute as “nonatomic” that means multiple threads can modify that property concurrently. If the attribute is “atomic”, the threads would be given access atomically. So “Atomic” is thread safe while “nonatomic” is thread unsafe. Atomic drastically hampers the performance so until and unless not needed you should never go for atomic attribute. ‘nonatomic ’ will do in most of the cases.
Which framework delivers event to custom object when app is in foreground?
The UIKit infrastructure takes care of delivering events to custom objects. As an app developer, you have to override methods in the appropriate objects to process those events.
Give example scenarios when an application goes into InActive state?
An app can get into InActive state when the user locks the screen or the system prompts the user to respond to some event e.g. SMS message, incoming call etc.