Thursday 27 December 2012

iOS interview questions and answers.

* What is SOAP [Simple Object Access Protocol]?
Ans. SOAP is an XML-based messaging protocol. It defines a set of rules for structuring messages that can be used for simple one-way messaging but is particularly useful for performing RPC-style (Remote Procedure Call) request-response dialogues. It is not tied to any particular transport protocol though HTTP is popular. Nor is it tied to any particular operating system or programming language so theoretically the clients and servers in these dialogues can be running on any platform and written in any language as long as they can formulate and understand SOAP messages. As such it is an important building block for developing distributed applications that exploit functionality published as services over an intranet or the internet.
* What are Web service protocols?
 Ans.  (a) HTTP GET, (b) HTTP POST & (c) SOAP.

* Can you give example for SOAP Format?  
Ans.
< soap:Envelope xmlns:soap="http://www.w3.org/2001/12/soap-envelope" soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding">
< soap:Header>
...
...
< /soap:Header>
< soap:Body>
...
...
< soap:Fault>
...
...
< /soap:Fault>
...
< /soap:Body>
< /soap:Envelope>

* what is the difference between Synchronous and Asynchronous web methods?  
Ans.  A synchronous method call waits for the method to complete before continuing with program flow,whereas an asynchronous method call will return immediately so that the program can perform other operations while the called method completes its work.
-Synchronous means that you trigger your NSURLConnection request and wait for it to be done.
Asynchronous means that you can trigger the request and do other stuff while NSURLConnection downloads data.
-Synchronous is very straightforward: you set it up, fire it, and wait for the data to come back. But your application sits there and does nothing until all the data is downloaded, some error occurs, or the request times out. If you're dealing with anything more than a small amount of data, your user will sit there waiting, which will not make for a good user experience.
-Asynchronous requires just a little more work, but your user can do other stuff while the request does its thing, which is usually preferable. You set up some delegate methods that let you keep track of data as it comes in, which is useful for tracking download progress. This approach is probably better for most usage cases.
Also refer this link : -  https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/URLLoadingSystem/Tasks/UsingNSURLConnection.html

* Difference between GET and POST methods -

 Ans.  •  Fundamental Difference is probably the Visibility - GET request is sent via the URL string (appended to the URI with a question-mark as separator), which is visible whereas POST request is encapsulated in the body of the HTTP request and can't be seen.
    •    Length - Since, GET request goes via URL, so it has a limitation for its length. It can't be more than 255 characters long (though this is browser dependent, but usually the max is 255 characters only). Whereas no such maximum length limitation holds for the POST request for the obvious reason that it becomes a part of the body of the HTTP request and there is no size limitation for the body of an HTTP request/response.
    •    Performance - GET request is comparatively faster as it's relatively simpler to create a GET request and the time spent in the encapsulation of the POST request in the HTTP body is saved in this case. In addition, the maximum length restriction facilitates better optimization of GET implementation.
    •    Type of Data - GET request is sent via URL string and as we all know that URL can be text-only, so GET can carry only text data whereas POST has no such restriction and it can carry both text as well as binary data.
    •    Caching/Bookmarking - again for the obvious reason that a GET request is nothing but an URL hence it can be cached as well as Bookmarked. No such luxuries with a POST request.
    •    FORM Default - GET is the default method of the HTML FORM element. To submit a FORM using POST method, we need to specify the method attribute and give it the value "POST".
    •    Data Set - GET requests are restricted to use ASCII characters only whereas POST requests can use the 'enctype' attribute with a value "multipart/form-data" to use
   Also refer this link:- http://www.diffen.com/difference/Get_vs_Post

* What is NSThread?
Ans. An NSThread object controls a thread of execution. Use NSThread when you want to have an Objective-C message run in its own thread of execution or if you need to terminate or delay the current thread. A thread is an executable unit. A task is made up of one or more threads. Each thread has its own execution stack and is capable of independent input/output. All threads share the virtual memory address space and communication rights of their task. When a thread is started, it is detached from its initiating thread. The new thread runs independently. That is, the initiating thread does not know the new thread's state.

Tuesday 11 December 2012

iOS interview questions and answers.

* What is iPhone OS?
Ans. 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.

* What is iPhone sdk?
Ans. 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.

* What is iPhone Architecture?
Ans. 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.

* What is MVC ? MVC Architecture of iPhone App.
 Ans. Here are the reasons why we should use the MVC (Model View Controller)design pattern.
    1.    They are 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.    They are 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.

* What are the ways to store data localy on device ?
 Ans. We store data localy in device through:
    1.    Plist.
    2.    NSUserDefaults.
    3.    SQLite.
    4.    CoreData.

* Difference between COCOA,COCOA touch and objective C ?
Ans. 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.

* Difference between shallow copy and deep copy?

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

* What is advantage of categories? What is difference between implementing a category and inheritance?
Ans. 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.

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

* What is polymorphism?
Ans. 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.

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

* How is the app delegate is declared by Xcode project templates?
Ans. App delegate is declared as a subclass of UIResponder by Xcode project templates.

* What is the purpose of UIWindow object?
Ans. The presentation of one or more views on a screen is coordinated by UIWindow object.

* Whats the difference between frame and bounds?
Ans. 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).

*  What is @interface?
Ans. It’s a keyword used to declare the Class.

* What is @implementation?
Ans. It’s a keyword used to define the Class.

* Garbage collector in iPhone?
Ans. iOS 5.0 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 is delegate?
Ans.  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 .

* What is @synthesize?
Ans.
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 are the features of iOS 6.0 ?
 Ans. Please hit on this link-
https://developer.apple.com/technologies/ios6/


* What is nonatomic ?
Ans.  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.

* What are the delegate methods of MKMapView ?
Ans. Firstly you have added the MapKit.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;

* What are the important delegate methods of NSXML parser?
Ans.
-DidStartElement
-FoundCharecters
-DidEndElement
-FoundError

* What is @dynamic and any place where it is used ?
Ans. 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 are the delegate methods of MKMapView ?
Ans.
1) - (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view
       calloutAccessoryControlTapped:(UIControl *)control
2) - (void)mapView:(MKMapView *)mapView didChangeUserTrackingMode:
      (MKUserTrackingMode)mode animated:(BOOL)animated
3) - (void)mapView:(MKMapView *)mapView didSelectAnnotationView:
      (MKAnnotationView *)view
4) - (void)mapView:(MKMapView *)mapView didUpdateUserLocation:
      (MKUserLocation *)userLocation
5) - (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:
      (id < MKAnnotation >)annotation