Pages

Sunday, 1 December 2013

iPhone Basic Interview Questions and Answers for Developers

iPhone Basic Interview Questions and Answers for Developers 

If you are preparing for iPhone technical interview, you must go through following iPhone interview questions and answers which are very basic for an iPhone developer and you should know all these basic iPhone concepts. Following iPhone interview questions and anwsers cover basic iPhone concepts like iPhone OS, SDK, Architecture, MVC design pattern, COCOA, COCOA Touch, Objective C, Shallow and Deep Copy in Objective C, difference between implementing a category and inheritance, Apple push notification service, When to use NSMutableArray and when to use NSArray, difference between frame and bounds, UIWindow object, Garbage collector in iPhone, nonatomic, @synthesize, delegate methods of MKMapView, types of parser and lot more...Lets have look on these iPhone basic interview questions and answers. 

1. What is iPhone OS? 

iPhone OS runs on iPhone and iPod touch devices. Hardware devices are managed by iPhone OS and provides the technologies needed for implementing native applications on the phone. The OS ships with several system applications such as Mail, Safari, Phone, which provide standard services to the user. 

2. 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.

3. What is iPhone Architecture? 

It is similar to MacOS X architecture. It acts as an intermediary between the iPhone and iPod hardware an the appearing applications on the screen. The user created applications never interact directly with the appropriate drivers, which protects the user applications from changes to the hardware.

4. 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.

5. What are the ways to store data localy on iPhone device?

We store data localy in device through:

1. Plist.
2. NSUserDefaults.
3. SQLite.
4. CoreData.

6. Difference between COCOA, COCOA touch and objective C?

Objective C is a dynamic programming language - a bit like C++ and a bit like Java.

Cocoa is the application framework for Mac OS X. Cocoa Touch is the application framework for iPhone and iPod Touch - very similar to Cocoa. 

Cocoa is commonly referred to as the combination of the Foundation and AppKit frameworks, while Cocoa Touch is the combination of the Foundation and UIKit frameworks. Cocoa and Cocoa Touch sit on top of other collections of frameworks to create the API stacks. The other layers are Media, Core Services and Core OS. The main difference between Cocoa and Cocoa touch is that the UI classes and APIs aren't the same as Mac OS X, so instead of NSTextField, you have UITextField. Many of the classes share the same functionality and can be ported quite easily by simply changing the class name, though most will require some more changes, but usually nothing too heavy. There are also some differences between the Foundation frameworks in Cocoa and Cocoa Touch, most commonly missing classes, eg, Cocoa has NSHost and Cocoa Touch doesn't.

7. Difference between shallow copy and deep copy?

Shallow copy is also known as address copy. In this process you only copy address not actual data while in deep copy you copy data. Suppose there are two objects A and B. A is pointing to a different array while B is pointing to different array. Now what I will do is following to do shallow copy.?Char *A = {‘a’,’b’,’c’};?Char *B = {‘x’,’y’,’z’};?B = A;?Now B is pointing is at same location where A pointer is pointing.Both A and B in this case sharing same data. if change is made both will get altered value of data.Advantage is that coping process is very fast and is independent of size of array.while in deep copy data is also copied. This process is slow but Both A and B have their own copies and changes made to any copy, other will copy will not be affected.

8. What is advantage of categories? What is difference between implementing a category and inheritance? 

You can add method to existing class even to that class whose source is not available to you. You can extend functionality of a class without subclassing. You can split implementation in multiple classes. While in Inheritance you subclass from parent class and extend its functionality.

9. Flow of push notification? 

Ans. 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.

10. What is polymorphism?

This is very famous question and every interviewer asks this. Few people say polymorphism means multiple forms and they start giving example of draw function which is right to some extent but interviewer is looking for more detailed answer. Ability of base class pointer to call function from derived class at runtime is called polymorphism. For example, there is super class human and there are two subclasses software engineer and hardware engineer. Now super class human can hold reference to any of subclass because software engineer is kind of human. Suppose there is speak function in super class and every subclass has also speak function. So at runtime, super class reference is pointing to whatever subclass, speak function will be called of that class. I hope I am able to make you understand.

11. When to use NSMutableArray and when to use NSArray?

Ans. 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.

12. How is the app delegate is declared by Xcode project templates?

App delegate is declared as a subclass of UIResponder by Xcode project templates.

13. What is the purpose of UIWindow object?

The presentation of one or more views on a screen is coordinated by UIWindow object.

14. Whats the difference between frame and bounds?

The frame of a view is the rectangle, expressed as a location (x,y) and size (width,height) relative to the superview it is contained within. The bounds of a view is the rectangle, expressed as a location (x,y) and size (width,height) relative to its own coordinate system (0,0).

15. What is @interface?

It’s a keyword used to declare the Class.

16. What is @implementation?

It’s a keyword used to define the Class.

17. 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.

18. What is delegate?

Delegate is an object that handles the events happening on an object. To do that delegate has to follow a protocol specifying the task it is going to handle.

19. 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.

20. 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.

21. What are the delegate methods of MKMapView?

Firstly you have added the storeKit framework in your xcode project then define the protocol as <MKMapviewDelegate> in .h file.

- (void)mapView:(MKMapView *)mapView regionWillChangeAnimated:(BOOL)animated;
- (void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated;
- (void)mapViewWillStartLoadingMap:(MKMapView *)mapView;
- (void)mapViewDidFinishLoadingMap:(MKMapView *)mapView;
- (void)mapViewDidFailLoadingMap:(MKMapView *)mapView withError:(NSError *)error;
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation;
- (void)mapView:(MKMapView *)mapView didAddAnnotationViews:(NSArray *)views;

22. What are the important delegate methods of NSXML parser?

-DidStartElement
-FoundCharecters
-DidEndElement
-FoundError

23. 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.

24. 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.

No comments:

Post a Comment