New-Krish-15

This is continuation post for iOS  Interview Questions for fresher‘s.list of  iOS interview questions helped  you to clear iOS/iPhone interviews

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

A: [block]1[/block]

*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 taskʼs memory footprint increasing unnecessarily. You can also consider creating pools with a narrower scope or use NSOperationQueue with itʼs 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.

iOS interview Questions for  Expert level

 

*Q:What is sandbox?

A:

For security reasons, iOS places each app (including its preferences and data) in a sandbox at install time. A sandbox is a set of fine-grained controls that limit the app’s access to files, preferences, network resources, hardware, and so on. As part of the sandboxing process, the system installs each app in its own sandbox directory, which acts as the home for the app and its data.

To help apps organize their data, each sandbox directory contains several well-known subdirectories for placing files. Above Figure shows the basic layout of a sandbox directory.

 

 

*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 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 can’t 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 itʼs added twice to the autorelease pool and when it it dequeued the autorelease pool calls release more than once.

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

*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: 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: Implement the following methods: retain, release, autorelease.

A:

-(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: What are all  the newly added frameworks iOS 4.3 to iOS 5.0?

A:

  •  Accounts
  •  CoreBluetooth
  •  CoreImage
  •  GLKit
  •  GSS
  •  NewsstandKit
  •  Twitter

*Q: What is Automatic Reference Counting (ARC) ?

A:

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 source’s 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

Let us know these list of  iOS interview questions helped  you to clear iOS/iPhone interviews.

  • Bharat Dodeja

    Very well explained. Thanks for sharing.

  • horseshoe7

    You should really update this article as many of the concepts are out of date. For example, asking questions about pre-ARC. Plus, you also imply that your expert level questions are things that experts need to know. They’re not that important.

  • fyell

    I noticed a bug in your code when synthesizing your own getter. You should be returning [[title retain] autorelease] (I’m assuming you’re synthesizing a property with a retain attribute since your setter is doing a retain). Since the setter releases the object, you could possibly run into a situation like this:

    NSString* myTitle = self.title;
    self.title = @”A Different Title”;

    NSLog(@”myTitle is %@”, myTitle);
    //the line above will crash because the setter released the object myTitle was referencing