Thursday, April 19, 2012

iPhone Interview Questions With Answers

Today i am going to write some important questions for iPhone. while i have read Apple docs, some books and developing apps  and so far got this useful information and sharing with you.
I hope its helpful for you. but still if you have any precious suggestion just let me know i'll try to update this page every-time.

So lets start from scratch..

                                                All About iPhone App Development..

1.  What is the iPhone?
Ans. The iPhone is an integrated cellular telephone and media player developed and marketed by Apple. its primary function as a cellular telephone, the iPhone includes a music and video player, digital camera, PDA, and an Internet communications suite. The iPhone runs Apple's OS-X operating system iOS.
The first iPhone was unveiled by Steve Jobs, then CEO of Apple, on January 9, 2007, and released on June 29, 2007.

2.What is iPhone SDK?
Ans. A software development kit (SDK) released by Apple that allows people to write applications for both the iPhone and the iPod Touch. The iPhone SDK includes the Xcode IDE, Instruments, iPhone simulator, frameworks and samples, compilers, Shark analysis tool, and more.

3. Define iPhone Architecture?
Ans. 

4. What is iOS?
Ans. iOS (iPhone OS) is a mobile operating system developed and distributed by Apple Inc. Originally released in 2007 for the iPhone and iPod Touch, it has since been extended to support other Apple devices such as the iPad and Apple TV.

5. What is Objective-c?
Ans. Objective-C is a reflective, object-oriented programming language that adds Smalltalk-style messaging to the C programming language also known as C with Classes.
it is used mostly on Apple's Mac OS X and iOS. Objective-C is the primary language used for Apple's Cocoa API, and it was originally the main language on NeXT's NeXTSTEP operating system.
Originally developed by the Stepstone Corporation, it was licensed by NeXT Computer (later acquired by Apple) .
 
6. What is Cocoa Framework?
Ans. Cocoa is an application environment for both the Mac OS X operating system and iOS, the operating system used on Multi-Touch devices such as iPhone, iPad, and iPod touch. It consists of a suite of object-oriented software libraries, a run-time system, and an integrated development environment.
Cocoa consists of the Foundation Kit, Application Kit, and Core Data frameworks, as included by Cocoa.h header file, as well as the libraries and frameworks included by those, such as the C standard library and the Objective-C run-time itself.
Cocoa applications are typically developed using the development tools provided by Apple, specifically Xcode and Interface Builder, using the Objective-C language.

7. Define iPhone Application Life Cycle ?
Ans.

8. What is Xcode ?
Ans. Xcode (formerly Project Builder) is Apple's free Integrated Development Environment (IDE) for MacOS X that supports writing in C, C++, Objective C, AppleScript and Java.
Introduced with Version 10.3 (Panther) of OS X in 2003. It is tightly integrated with Interface Builder which enables the simple construction of GUIs for Mac Applications.
                                                                     or
Xcode is a suite of tools, developed by Apple, for developing software for Mac OS X and iOS.

9. What is Interface Builder?
Ans. Interface Builder is a software development application for Apple's Mac OS X operating system which is part of Xcode.
Interface Builder is an application that allows you, the developer, to create the Graphical User Interface (GUI) with the help of Cocoa and Carbon.The resulting interface is stored as a .nib file, short for NeXT Interface Builder, or more recently, as a .xib file.

10.What is difference between .xib and .nib?
Ans. When building an application, these files are copied into the app's bundle and are loaded at run-time to provide the user interface for the application. xib files are compiled into nibs when the application is built.
XIB (XML Interface Builder)
  •  It was new file with .xib format, introduced in accordance with Leopard( Xcode 3.0 ) in 2007.
  •  XIB is not like package, text-based XML file with ".xib" extension, used by XCode, Interface Builder(IB) by default.
  •  These are more version control friendly.
  • Interface Builder is a tool for editing XIB's file.
NIB (NeXT Interface Builder)
  • These files are archives with ".nib" extension, loaded by XCode application.
  • It is of 2 types:- (a) Keyed, (b) Non-keyed.
  • It can be edited in IB, which is in non-human-readable binary format.
11. What are the (.h) and (.m) files?
Ans. .h (header files) contain class, type, function, and constant declarations. So no actual code. Header files are there to let (for instance) xcode know what methods and properties are declared in that specific class.
.m (Class  implementation file) is contains all the implementation details of all the functions declared in .h. It also contains declaration and implementation of private functions that outside classes cannot use, or should not care about.

12.What is MVC in iOS?
Ans. A design pattern in which the model (any data in your program), the view (what the user sees), and the controller (a layer that handles all interaction between the view and model) are separated in such a manner that modifying either the view or model component of your program has no effect on one another.
Model :The model contains the data.
View : The view displays information contained in the model.
Controller : the controller is responsible for accessing data from the model and displaying it on the view.


13. What stands for IBOutlet and IBAction?
Ans. IBAction and IBOutlet are macros defined to denote variables and methods that can be referred to in Interface Builder.
IBOutlet – special instance variable that references another object. A message can be sent through an outlet. Interface Builder recognizes them. An IBOutlet is for hooking up a property to a view when designing your XIB.
IBAction – a special method triggered by user-interface objects. Interface Builder recognizes them. An IBAction is for hooking a method (action) up to a view when designing your XIB.

14. Outline the class hierarchy for a UIButton until NSObject.
Ans.UIButton inherits from UIControl, UIControl inherits from UIView, UIView inherits from UIResponder, UIResponder inherits from the root class NSObject
UIButton → UIControl → UIView → UIResponder → NSObject

15. What's the difference between delegate and data source?
Ans. Delegate: A delegate is just an object that another object sends messages to when certain things happen, so that the delegate can handle application-specific details the original object wasn't designed for. It's a way of customizing behavior without sub-classing.
Data Source: The data source protocol defines an API that instances of these (and other) classes may use to get the data to display in the view.
The data-source supplies the data, the delegate supplies the behavior.

16. What is Difference between Simulator and Emulator ?
Ans. A simulator is a system that behaves similar to something else, but is implemented in an entirely different way. It provides the basic behavior of a system but may not necessarily abide by all of the rules of the system being simulated. It is there to give you an idea about how something works.

Think of a flight simulator as an example. It looks and feels like you are flying an airplane, but you are completely disconnected from the reality of flying the plane, and you can bend or break those rules as you see fit. E.g.; Fly an Airbus A380 upside down between London and Sydney without breaking it.

An emulator is a system that behaves exactly like something else, and abides by all of the rules of the system being emulated. It is effectively a complete replication of another system, right down to being binary compatible with the emulated system's inputs and outputs, but operating in a different environment to the environment of the original emulated system. The rules are fixed, and cannot be changed or the system fails.

17. What is the difference between drain, release, dealloc and retain in Objective-C?
Ans.
  • retain increase the reference count on an object
  • release decreases the reference on an object
  • drain is used in place of release on ONLY for NSAutoreleasePool objects due to some arcana related to the Objective C garbage collection
  • dealloc is called by the system once the retainCount of an object hits 0. It is where you clean up various things your object has (like a deconstructor or finalizer). You should NEVER call it directly, except for calling [super dealloc] at the end of your dealloc routines.
 18.  What is @synthesize and @property ?
Ans. Just as there are two parts to a class (@interface and @implementation) there are also two parts to this shortcut. The first part, @property, is the part associated with the interface and second part, @synthesize, is the part associated with the implementation.
@property : The format is @property (attributes) type name; where attributes are optionally included from the list below, type is the variable type being declared, and the name is the name of the variable.
@synthesize :Once we’ve declared the properties, we need to actually add the code to implement our methods.

19. Define @protocol ?
Ans. A protocol is an important language feature in Objective-C. Protocols provide, among other things, the ability to realize multiple inheritance in a single-inheritance language.
Think of a protocol as an interface in the Java language. Just as classes in Java can implement multiple interfaces, so can classes in Objective-C adopt multiple protocols.
A protocol is just a list of methods. Each method in this list can be tagged as either required
(@required, the default) or optional (@optional). If a class adopts a protocol, it must
implement at least all required methods in that protocol.

20. how to achieve getter and setter property in iOS?
Ans. by using these tow preprocessor directives @property and @synthesize we can achieve getter and setter.

21. What is Automatic Reference Counting (ARC) ?
Ans.Automatic reference counting (ARC) was introduced in the iOS 5 sdk to free Objective-C programmers from having to handle memory management by making memory management the job of the compiler.

If you developer with Objective-C prior to the iOS 5 SDK or talked to Obj-C programmers then you are probably aware of how tedious task memory management could become.  When using ARC there is no need for retain and release calls, and not only that in many cases ARC can provide a significant performance increase.

22 What is .plist file and explain about it is usage?
Ans. Property list files are often used to store a user's settings. They are also used to store information about bundles and applications.

23. Difference between viewDidLoad, viewWillAppear, viewDidAppear and viewLoad?
Ans.loadView is the method in UIViewController that will actually load up the view and assign it to the "view" property. This is also the location that a subclass of UIViewController would override if you wanted to programatically set up the "view" property.



ViewDidLoad - Whenever I'm adding controls to a view that should appear together with the view, right away, I put it in the ViewDidLoad method. Basically this method is called whenever the view was loaded into memory. So for example, if my view is a form with 3 labels, I would add the labels here; the view will never exist without those forms.This is called after loadView is called.

ViewWillAppear: I use ViewWillAppear usually just to update the data on the form. So, for the example above, I would use this to actually load the data from my domain into the form. Creation of UIViews is fairly expensive, and you should avoid as much as possible doing that on the ViewWillAppear method, becuase when this gets called, it means that the iPhone is already ready to show the UIView to the user, and anything heavy you do here will impact performance in a very visible manner (like animations being delayed, etc).

ViewDidAppear: Finally, I use the ViewDidAppear to start off new threads to things that would take a long time to execute, like for example doing a webservice call to get extra data for the form above.The good thing is that because the view already exists and is being displayed to the user, you can show a nice "Waiting" message to the user while you get the data

24. Difference between nil and Nil and NULL and [NSNull null] ?
Ans.They differ in their types. They're all zero,
  • NULL : is a c pointer, Void * (0) ,
  • If you want to set char * to 0 then you would set it to NULL
  • nil  : an object pointer or id (0) 
  • if you want to set a view controller to 0 then you would set it to nil
  • Nil  : Class pointer == (Class ) 0
  • [NSNull null] : use for the object for which “nil” is not allowed (ex. NSArray). 
25. Class methods vs Instance methods and visibility of methods ?
Ans.Class methods (most languages use the keyword static)
  • Operate on Class variables (they can not access instance variables)
  • Do not require an object to be instantiated to be applied
  • (+) denotes a class method
Instance methods
  • Operate on instances variables and class variables
  • Must have an instanciated object to operate on
  • (-) denotes an instance method.

26. Define Visibility in Objective C?
Ans. Visibility :The Objective C has variable by default @protected. But methods are not used with access specifier they are public by default. To hide any method from out side . Declare and Implement    it in .m file using category .

27. what is deep copy and shallow copy?
Ans. A shallow copy is a copy of an object in which its instance variables still point to the same memory location as the original object's ivars.
A deep copy is a copy in which copies of the instance variables are also made.

28. Difference between UIView and UIViewController ?
Ans.The difference is due to the Model-View-Controller -pattern (MVC) used throughout the Cocoa Touch. MVC is used to separate the application data from the way it is displayed on screen:

-Model refers to the application data model, such as a database of names, dates of birth and so on.

-View refers to the actual user interface elements that are displayed on screen. A UIView, UIButton, UITableView etc. are all examples of View elements.

-Controller refers to "mediating" objects that act between the Model(s) and the View(s). Controllers usually contain most of the application logic such as handling user input, filtering data from the Model based on user input, and then updating the View elements to display the correct values.
also check here..

29. Difference between release and autorelease ?
Ans. Objective-c is reference counted, so objects are deleted when the reference count reaches 0. release reduces the reference-count immediately, autorelease reduces it when the autorelease-pool is popped.

30. Multitasking support is available from which version?
Ans.iOS 4.0

31. Whats the difference between a NSArray and a NSMutableArray?
Ans. NSArray’s contents can not be modified once it’s been created whereas a NSMutableArray can be modified as needed, i.e items can be added/removed from it.

32. 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).

33. Is a delegate retained?
Ans.  No, the delegate is never retained! Ever!

34. Explain retain counts?
Ans.Retain counts are the way in which memory is managed in Objective-C. When you create an object, it has a retain count of 1. When you send an object a retain message, its retain count is incremented by 1.
When you send an object a release message, its retain count is decremented by 1. When you send an object a autorelease message, its retain count is decremented by 1 at some stage in the future. If an object’s retain count is reduced to 0, it is deallocated.

35.  Difference between protocol in objective c and interfaces in java?
Ans.delegate protocol needs to be defined as such

@protocol
          //methods
@end

it can be put in any .h class, you just need to import i t whenever you are going to use it.

A protocol is not like a java interface, a protocol is an adapter that allows two classes to works together. Basically it says, if you want class A to send you messages about its state and actions these are the methods it will call on its delegate that you must implement. Its not like an interface because an interface says if you want to subclass this class you must implement these methods, the protocol says if you want to interact with this class you must implement these methods, so its somewhat different.

36. What is purpose of delegates?
Ans.A delegate is just an object that another object sends messages to when certain things happen, so that the delegate can handle app-specific details the original object wasn't designed for. It's a way of customizing behavior without sub-classing.

37. What is push notification?
Ans. In iOS, apps can’t do a lot in the background. Apps are only allowed to do limited set of activities so battery life is conserved.
But what if something interesting happens and you wish to let the user know about this, even if they’re not currently using your app?

For example, maybe the user received a new tweet, their favorite team won the game, or their dinner is ready. Since the app isn’t currently running, it cannot check for these events.
Luckily, Apple has provided a solution to this. Instead of your app continuously checking for events or doing work in the background, you can write a server-side component to do this instead.
And when an event of interest occurs, the server-side component can send the app a push notification! There are three things a push notification can do:
  • Display a short text message
  • Play a brief sound
  • Set a number in a badge on the app’s icon

38. How can we achieve singleton pattern in iOS?
Ans. The Singleton design pattern ensures a class only has one instance, and provides a global point of access to it. The class keeps track of its sole instance and ensures that no other instance can be created. Singleton classes are appropriate for situations where it makes sense for a single object to provide access to a global resource.
A singleton class returns the same instance no matter how many times an application requests it.
check here

39. Difference between method and selector?
Ans. Selector - a Selector is the name of a method.
Method - a method is a combination of a selector and an implementation.

40. What is a selector, how to do a perform selector?
Ans. Selector can either be a name of method or a message to an object when used in the source code. And SEL is the complied form of a Selector. Also remember that all methods with the same name have the same selector. We can also use use selector to invoke a method on object.

41. What is lazy loading?
Ans. Lazy Loading is a programming practice in which you only load or initialize an object when you first need it. This can potentially give you a big performance boost, especially if you have a lot of components in your application.

42. Give us example of what are Delegate methods and what are Data Source methods of UITableview.
Ans. UITableview's Delegate Methods :
The delegate of a UITableView object must adopt the UITableViewDelegate protocol. Optional methods of the protocol allow the delegate to manage selections, configure section headings and footers, help to delete and reorder cells, and perform other actions.
All the Methods are..
Configuring Rows for the Table View
    – tableView:heightForRowAtIndexPath:
    – tableView:indentationLevelForRowAtIndexPath:
    – tableView:willDisplayCell:forRowAtIndexPath:

Managing Accessory Views
    – tableView:accessoryButtonTappedForRowWithIndexPath:
    – tableView:accessoryTypeForRowWithIndexPath: Deprecated in iOS 3.0

Managing Selections
    – tableView:willSelectRowAtIndexPath:
    – tableView:didSelectRowAtIndexPath:
    – tableView:willDeselectRowAtIndexPath:
    – tableView:didDeselectRowAtIndexPath:

Modifying the Header and Footer of Sections
    – tableView:viewForHeaderInSection:
    – tableView:viewForFooterInSection:
    – tableView:heightForHeaderInSection:
    – tableView:heightForFooterInSection:

Editing Table Rows
    – tableView:willBeginEditingRowAtIndexPath:
    – tableView:didEndEditingRowAtIndexPath:
    – tableView:editingStyleForRowAtIndexPath:
    – tableView:titleForDeleteConfirmationButtonForRowAtIndexPath:
    – tableView:shouldIndentWhileEditingRowAtIndexPath:

Reordering Table Rows
    – tableView:targetIndexPathForMoveFromRowAtIndexPath:toProposedIndexPath:

Copying and Pasting Row Content
    – tableView:shouldShowMenuForRowAtIndexPath:
    – tableView:canPerformAction:forRowAtIndexPath:withSender:
    – tableView:performAction:forRowAtIndexPath:withSender:

UITableview's Data Source Methods : The NSTableViewDataSource protocol declares the methods that an instance of NSTableView uses to provide the data to a table view and allow editing of the contents of its data source object.
 All the Methods are..
Getting Values
    – numberOfRowsInTableView:
    – tableView:objectValueForTableColumn:row:

Setting Values
    – tableView:setObjectValue:forTableColumn:row:

Implementing Pasteboard Support
    – tableView:pasteboardWriterForRow:

Drag and Drop
    – tableView:acceptDrop:row:dropOperation:
    – tableView:namesOfPromisedFilesDroppedAtDestination:forDraggedRowsWithIndexes:
    – tableView:validateDrop:proposedRow:proposedDropOperation:
    – tableView:writeRowsWithIndexes:toPasteboard:
    – tableView:draggingSession:willBeginAtPoint:forRowIndexes:
    – tableView:updateDraggingItemsForDrag:
    – tableView:draggingSession:endedAtPoint:operation:

Sorting
    – tableView:sortDescriptorsDidChange:

43. Can we use one Table View with two different Data Sources? How you will achieve this?
Ans. A UITableView has something called a dataSource but you seem to be referring, essentially, to two different sets of data.
I'd have three arrays.
  • currentlyViewedArray
  • datasetOneArray
  • datasetTwoArray
In the dataSource methods, use the currentlyViewedArray as the source of the table's data.
Then, set the currentlyViewedArray to whichever array you want to view:
self.currentlyViewedArray = self.datasetOneArray;
[theTableView reloadData];
You can use the UISegmentedControl to switch between the two arrays.

44. What is atomic and non-atomic? Which one is safer? Which one is default??
Ans.  Atomic guarantees that access to the property will be performed in an atomic manner.In nonatomic, no such guarantees are made. Thus, nonatomic is considerably faster than "atomic".
  • so "atomic"will be thread safe.
  • "atomic" is the default behavior

45. What is the NSCoder class used for?
Ans. NSCoder is an abstractClass which represents a stream of data. They are used in Archiving and Un-archiving objects. NSCoder objects are usually used in a method that is being implemented so that the class conforms to the protocol. (which has something like encodeObject and decodeObject methods in them).

46. How can you store data in iPhone applications?
Ans.You have a few different ways to store application data on your iPhone.
SQLite DB - DB Used by iOS development, you can interact with this directly depending on your preferences (e.g. you want to use SQL statements).
CoreData - Abstraction to SQLite DB so you can remove SQL statements and use the API instead. Advantage of this is its compatibility with the Cocoa API. In our production applications we use CoreData over SQLite.
File System - You can store files directly here and use a convention. You might also want to read about using the cache folder iOS development for temporary data.
XML - Case to case. In commercial application, we only use XML for interfacing between systems. E.g. iPad to Cloud server.
UserDefault - only for parameters
NSUserDefaults is a convenient tool for storing user credentials but is not intended for larger volumes of data.
Plist files are another option if you want to manage your own storage on the file system. NSArray and NSDictionary provide methods for writing and reading those collections to and from plist files as long as you can store all of your data in one of the supported plist data types.

47. What are commonly used NSObject class methods?
Ans. The NSObject protocol groups methods that are fundamental to all instances. defined in the Foundation Kit.
Method Names
                           Identifying and comparing instances

isEqual:

hash
self

Identifying class and superclass
class

superclass

Determining allocation zones zone

Sending messages determined at run time

perform:

perform:withObject:
perform:withObject:withObject:

Identifying proxies isProxy


Testing inheritance relationships isKindOfClass:

isMemberOfClass:

Testing for protocol conformance

conformsToProtocol:

Testing class functionality respondsToSelector:


Managing reference counts retain

release
autorelease
retainCount

48. Steps to deploy an app into the device ?
Ans. nice steps here..

49.Difference between C++ and Objective C ?
Ans.
C++ is Bjarne Stroustroup's language based on adding classes and meta programming to C in such a way that puts most additional work into the compiler, and relies on least possible effort at run time.

Objective-C is Brad Cox's language based on adding a Smalltalk-style dynamic message-passing run time library to C, with a small amount of syntax addition to make it easier to use.

so the differences are..
  • C++ has multiple inheritance. Objective C does not. Instead, it allows the user to define a protocol.
  • C++ uses bool, true and false, Objective-C uses BOOL, YES and NO.
  • Objective-C uses "selectors" as an approximate equivalent to function pointers.
  • Objective-C will happily let you send a message to nil, unlike C++ which will crash if you try to call a member function of NULL.
  • Objective-C lacks the namespace and templates feature of C++.
or you may check this and this apple doc..

50. What is difference between Objective C and Java ?
Ans.

51. What is the difference between a synchronous and an asynchronous request ?
Ans. A program does not wait for response after requesting an asynchronous call whereas synchronous does so.

52. What is advantage of using RESTful web-services?
Ans. REST has advantages when:
- You have a set of resources that you want to manipulate.
- You want to support navigation between resources.
- You need scalability.RESTful web services are tyically stateless and therefore easily scalable.
- You want to improve performance by caching web service request results at some point between the service and the consumer.

53. What is the difference between REST and SOAP protocols?
Ans.REST (Representational State Transfer) defines a set of architectural principles by which you can design Web services that focus on a system's resources, including how resource states are addressed and transferred over HTTP by a wide range of clients written in different languages.

SOAP (Simple Object Access Protocol) is a simple XML-based protocol to let applications exchange information over HTTP.
                       Or
SOAP is a protocol for accessing a Web Service.
SOAP is for communication protocol between applications
SOAP is a format for sending messages
SOAP communicates via Internet
SOAP is platform independent
SOAP is language independent
SOAP is based on XML
SOAP is simple and extensible
SOAP allows you to get around firewalls

54 Explain the types of Notification in iPhone ?
Ans. iOS apps can provide three types of notifications:
  • Sounds: Plays an audible alert
  • Alerts/Banners: Displays an alert or banner on the screen
  • Badges: Displays an image or number on the application icon

55. Difference between sax parser and dom parser ?
Ans. SAX (Simple API for XML):
1. Parses node by node
2. Doesn't store the XML in memory
3. We cant insert or delete a node
4. Top to bottom traversing
DOM (Document Object Model):
1. Stores the entire XML document into memory before processing
2. Occupies more memory
3. We can insert or delete nodes
4. Traverse in any direction.

56. Can you just explain about memory management in iOS?
Ans. Refer: iOS Memory Management

57. what is the File Owner, Responder Chain, becomeFirstResponder?
Ans. The File Owner is an instantiated, run-time object that owns the contents of your nib and it's outlets/actions when the nib is loaded.
A responder is an object that can respond to events and handle them.
If the first responder cannot handle an event or action message, it forwards it to the “next responder” in a linked series called the responder chain.

The responder chain is the order in which various objects are given the chance to handle an event. In a simple case, suppose we have a button in a NSView in a NSWindow in a NSApp. When the button is clicked; the button will have the first opportunity to handle the event, then its controller, then the NSView, then its controller, then the NSWindow, then its delegate, then the NSApp and its delegate. In this way, an object is first given a chance to handle the event, then its controller/delegate, then the container of the object and so on. 

58. What are all  the newly added frameworks iOS 4.3 to iOS 5.0?
Ans  • Accounts
        • CoreBluetooth
        • CoreImage
        • GLKit
        • GSS
        • NewsstandKit
        • Twitter

59. What are sensors in iPhone?
Ans. 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.

60. What are the location services?
Ans. Applications such as Maps, camera and compass are allowed to use the information from cellular, Wi-Fi and Global Positioning System networks for determining the approximate locations.
The location is displayed on the screen, using a blue marker.


cheers!!
I'd love to hear your thoughts!!

10 comments: