iOS DEVELOPER Interview Questions
iOS DEVELOPER Interview Questions
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. You will come to know more of the nuances between the two and will soon be able to instinctively know what will work on an iPhone with little/no modification and what will require some work to port between, but it's not that difficult.
Where can you test Apple iPhone apps if you dont have the device? A. 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. Q2. Does iOS support multitasking? A. 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. Q3. Which JSON framework is supported by iOS? A. SBJson framework is supported by iOS. It is a JSON parser and generator for Objective-C. SBJson provides flexible APIs and additional control that makes JSON handling easier. Q4. What are the tools required to develop iOS applications? A. iOS development requires Intel-based Macintosh computer and iOS SDK. Q5. Name the framework that is used to construct applications user interface for iOS. A. The UIKit framework is used to develop applications user interface for iOS. UIKit framework provides event handling, drawing model, windows, views, and controls specifically designed for a touch screen interface. Q6. Name the application thread from where UIKit classes should be used? A. UIKit classes should be used only from an applications main thread. Note: The derived classes of UIResponder and the classes which manipulate applications user interface should be used from applications main thread. Q7. Which API is used to write test scripts that help in exercising the application's user interface elements? A. UI Automation API is used to automate test procedures. Tests scripts are written in JavaScript to the UI Automation API. This in turn simulates user interaction with the application and returns log
App States
Q11. When an app is said to be in not running state? A. An app is said to be in 'not running' state when: - it is not launched. - it gets terminated by the system during running. Q12. Assume that your app is running in the foreground but is currently not receiving events. In which sate it would be in? A. An app will be in InActive state if it is running in the foreground but is currently not receiving events. An app stays in InActive state only briefly as it transitions to a different state. Q13. Give example scenarios when an application goes into InActive state? A. 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. Q14. When an app is said to be in active state? A. An app is said to be in active state when it is running in foreground and is receiving events. Q15. Name the app sate which it reaches briefly on its way to being suspended. A. An app enters background state briefly on its way to being suspended. Q16. Assume that an app is not in foreground but is still executing code. In which state will it be in? A. Background state. Q17. An app is loaded into memory but is not executing any code. In which state will it be in? A. An app is said to be in suspended state when it is still in memory but is not executing any code. Q18. Assume that system is running low on memory. What can system do for suspended apps? A. In case system is running low on memory, the system may purge suspended apps without notice. Q19. How can you respond to state transitions on your app? A. On state transitions can be responded to state changes in an appropriate way by calling corresponding methods on app's delegate object. For example: applicationDidBecomeActive method can be used to prepare to run as the foreground app. applicationDidEnterBackground method can be used to execute some code when app is running in the background and may be suspended at any time. applicationWillEnterForeground method can be used to execute some code when your app is moving out of the background applicationWillTerminate method is called when your app is being terminated. Q20. List down app's state transitions when it gets launched. A. Before the launch of an app, it is said to be in not running state.
When an app is launched, it moves to the active or background state, after transitioning briefly through the inactive state. Q21. Who calls the main function of you app during the app launch cycle? A. During app launching, the system creates a main thread for the app and calls the apps main function on that main thread. The Xcode project's default main function hands over control to the UIKit framework, which takes care of initializing the app before it is run.
render their content. Custom layer objects can also be added to the interface to implement complex animations and other types of sophisticated visual effects.
BEGINNER
Q: How would you create your own custom view? A: Subclass the UIView class. Q: Whats fast enumeration? A: Fast enumeration is a language feature that allows you to enumerate over the contents of a collection. (Your code will also run faster because the internal implementation reduces message send overhead and increases pipelining potential.) Q: Whats a struct? A: A struct is a special C data type that encapsulates other pieces of data into a single cohesive unit. Like an object, but built into C. Q: Whats the difference between a NSArray and a NSMutableArray? A: A NSArrays contents can not be modified once its been created whereas a NSMutableArray can be modified as needed, i.e items can be added/removed from it. Q: Explain retain counts. A: 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 objects retain count is reduced to 0, it is deallocated. Q: Whats the difference between frame and bounds? A: 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). Q: Is a delegate retained? A: No, the delegate is never retained! Ever!
INTERMEDIATE
A: Yes the object is retained. It creates a timer that calls a selector on the current threads run loop. It may not be 100% precise time-wise as it attempts to dequeue the message from the run loop and perform the selector.
Q: Can you explain what happens when you call autorelease on an object? A: When you send an object a autorelease message, its retain count is decremented by 1 at some stage in the future. The object is added to an autorelease pool on the current thread. The main thread loop creates an autorelease pool at the beginning of the function, and release it at the end. This establishes a pool for the lifetime of the task. However, this also means that any autoreleased objects created during the lifetime of the task are not disposed of until the task completes. This may lead to the tasks memory footprint increasing unnecessarily. You can also consider creating pools with a narrower scope or use NSOperationQueue with its own autorelease pool. (Also important You only release or autorelease objects you own.) Q: Whats the NSCoder class used for? A: NSCoder is an abstractClass which represents a stream of data. They are used in Archiving and Unarchiving 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). Q: Whats an NSOperationQueue and how/would you use it? A: The NSOperationQueue class regulates the execution of a set of NSOperation objects. An operation queue is generally used to perform some asynchronous operations on a background thread so as not to block the main thread. Q: Explain the correct way to manage Outlets memory A: Create them as properties in the header that are retained. In the viewDidUnload set the outlets to nil(i.e self.outlet = nil). Finally in dealloc make sure to release the outlet.
ADVANCED
Q: Is the delegate for a CAAnimation retained? A: Yes it is!! This is one of the rare exceptions to memory management rules. Q: What happens when the following code executes? 1 Ball *ball = [[[[Ball alloc] init] autorelease] autorelease];
and when it it dequeued the autorelease pool calls release more than once.
Q: Outline the class hierarchy for a UIButton until NSObject. A: UIButton inherits from UIControl, UIControl inherits from UIView, UIView inherits from UIResponder, UIResponder inherits from the root class NSObject Q: Explain the difference between NSOperationQueue concurrent and non-concurrent. A: In the context of an NSOperation object, which runs in an NSOperationQueue, the terms concurrent and non-concurrent do not necessarily refer to the side-by-side execution of threads. Instead, a non-concurrent operation is one that executes using the environment that is provided for it while a concurrent operation is responsible for setting up its own execution environment.