You are on page 1of 10

Development OS Programming Refernece Tips & Tricks Tech News Contact for Support

Home Development iOS iOS Interview Questions & answers for experienced developers

iOS Interview Questions & answers for experienced developers


Published on January 1, 2013 by Krish

This is continuation post for iOS Interview Questions for freshers.


*Q: A: *Q: A:

Explain the options and bars available in xcode 4.x workspace window ?

If I call performSelector:withObject:afterDelay: is the object retained?

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: A:

Can you explain what happens when you call autorelease on an object?

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: A:

Whats the NSCoder class used for?

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: A:

Whats an NSOperationQueue and how/would you use it?

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: A:

Explain the correct way to manage Outlets memory.

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.

iOS Questions for Expert level


*Q:Is A:

the delegate for a CAAnimation retained?

Yes it is!! This is one of the rare exceptions to memory management rules.
*Q:

What is dynamic?

A:You

use the @dynamic keyword to tell the compiler that you will fulfill the API contract implied by a property either by providing method implementations directly or at runtime using other mechanisms such as dynamic loading of code or dynamic method resolution. It suppresses the warnings that the compiler would otherwise generate if it cant find suitable implementations. You should use it only if you know that the methods will be available at runtime.
*Q:

What happens when the following code executes?

Ball *ball = [[[[Ball alloc] init] autorelease] autorelease];


A:

It will crash because its added twice to the autorelease pool and when it it dequeued the autorelease pool calls release more than once.

Explain the difference between NSOperationQueue concurrent and nonconcurrent.


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

Implement your own synthesized methods for the property NSString *title.
*Q: A:

Well you would want to implement the getter and setter for the title object. Something like this: view source print? - (NSString*) title // Getter method { return title; } - (void) setTitle: (NSString*) newTitle //Setter method { if (newTitle != title) { [title release]; title = [newTitle retain]; // Or copy, depending on your needs. } }
*Q: A:

Implement the following methods: retain, release, autorelease.

-(id)retain {

NSIncrementExtraRefCount(self); return self; } -(void)release { if(NSDecrementExtraRefCountWasZero(self)) {NSDeallocateObject(self); } } -(id)autorelease { // Add the object to the autorelease pool [NSAutoreleasePool addObject:self]; return self; }
*Q: A: *Q: A:

What are all the newly added frameworks iOS 4.3 to iOS 5.0?

Accounts CoreBluetooth CoreImage GLKit GSS NewsstandKit Twitter

What is Automatic Reference Counting (ARC) ?

ARC is a compiler-level feature that simplifies the process of managing the lifetimes of Objective-C objects. Instead of you having to remember when to retain or release an object, ARC evaluates the lifetime requirements of your objects and automatically inserts the appropriate method calls at compile time.
*Q:

What is the difference between retain & assign?

A:

Assign creates a reference from one object to another without increasing the sources retain count.
if (_variable != object) { [_variable release]; _variable = nil; _variable = object; }

Retain creates a reference from one object to another and increases the retain count of the source object.
if (_variable != object) {

[_variable release];
_variable = nil; _variable = [object retain]; }

Page : 3 You may be interested in this:

iOS interview Questions with Answers The following list of questions and answers may help you to clear iOS/iPhone interviews. iOS in ...

iOS Memory Management FAQ

What is Memory management in iOS? Memory management is the programming discipline of m ...

How to Enable NSZombies in xcode 4.2 and lower versions. One of the best tool for debugging memory problems in iOS is NSZombie. What is NSZombies: ...

iPhone interview questions with answers part- II This is continuation for iOS interview questions with answers. *Q: What is Controller Object? ...

How to make Xcode faster by solving Xcode slow issues with xcode 4.x How to make xcode faster Buying more memory. Disable indexing if you are building out huge p ...
By Blogsdna

Share this:

Twitter Facebook LinkedIn Google +1 Email Print

iPhone interview questions wit... iOS interview Questions with A... 1 Comment

Search in site

Subscribe for Updates

Register Log in Entries RSS Comments RSS WordPress.org

iOS Interview Questions


Posted by Jeff . Filed under Developers, iPhone OS, Objective-C | 64 Comments

Ive been interviewing alot of people recently for iPhone and iPad developer positions. Asides from algorithm runtime problems, I ask some general iOS questions. So being the kind person I am, im posting some questions based on difficulty and expected answers. NOTE: If you want to test your iOS skills before you read the answers, heres a text file just with questions iOS Interview questions 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

Q: If I call performSelector:withObject:afterDelay: is the object retained? 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];

A: It will crash because its added twice to the autorelease pool 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 nonconcurrent. 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. Q: Implement your own synthesized methods for the property NSString *title. A: Well you would want to implement the getter and setter for the title object. Something like this:
1 - (NSString*) title { 2 return title; 3} 4 - (void) setTitle: (NSString*) newTitle { 5 if (newTitle != title) { 6 [title release]; title = [newTitle retain]; // Or copy, depending on your needs. 8 } 7 9}

Q: Implement the following methods: retain, release, autorelease. A:


01 -(id)retain { 02 NSIncrementExtraRefCount(self); 03 04 05 } 06 07 -(void)release { 08 09 10 if(NSDecrementExtraRefCountWasZero(self)) { NSDeallocateObject(self); return self;

11 } 12 } 13 14 -(id)autorelease { 15 16 17 18 19 } return self; // Add the object to the autorelease pool [NSAutoreleasePool addObject:self];

Hopefully some of these questions will help someone get a job! :)

You can follow me on Twitter @jeffhodnett for random daily iOS/tech stuff. Thanks to @damiendeville and @stuartcrook for their excellent insight for some of these questions.