iOS Interview Q&A



information copied from :


Development Basics

Q1. Where can you test Apple iPhone apps if you don’t 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 application’s user interface for iOS.
A. The UIKit framework is used to develop application’s 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 application’s main thread.  Note: The derived classes of UIResponder and the classes which manipulate application’s user interface should be used from application’s 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 information to the host computer.

App States and Multitasking

Q8. Why an app on iOS device behaves differently when running in foreground than in background?
A. An application behaves differently when running in foreground than in background because of the limitation of resources on iOS devices.

Q9. How can an operating system improve battery life while running an app?
A. An app is notified whenever the operating system moves the apps between foreground and background.  The operating system improves battery life while it bounds what your app can do in the background. This also improves the user experience with foreground app.

Q10. Which framework delivers event to custom object when app is in foreground?
A. The UIKit infrastructure takes care of delivering events to custom objects. As an app developer, you have to override methods in the appropriate objects to process those events.

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 app’s 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.

Core App Objects

Q22. What is the use of controller object UIApplication?
A. Controller object UIApplication is used without subclassing to manage the application event loop.
It coordinates other high-level app behaviors.
It works along with the app delegate object which contains app-level logic.

Q23. Which object is create by UIApplicationMain function at app launch time?
A. The app delegate object is created by UIApplicationMain function at app launch time. The app delegate object’s main job is to handle state transitions within the app.

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

Q25. What happens if IApplication object does not handle an event?
A. In such case the event will be dispatched to your app delegate for processing.

Q26. Which app specific objects store the app’s content?
A. Data model objects are app specific objects and store app’s content. Apps can also use document objects to manage some or all of their data model objects.

Q27. Are document objects required for an application? What does they offer?
A. Document objects are not required but are very useful in grouping data that belongs in a single file or file package.

Q28. Which object manage the presentation of app’s content on the screen?
A. View controller objects takes care of the presentation of app’s content on the screen. A view controller is used to manage a single view along with the collection of subviews. It makes its views visible by installing them in the app’s window.

Q29. Which is the super class of all view controller objects?
A. UIViewController class. The functionality for loading views, presenting them, rotating them in response to device rotations, and several other standard system behaviors are provided by UIViewController class.

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

Q31. How do you change the content of your app in order to change the views displayed in the corresponding window?
A. To change the content of your app, you use a view controller to change the views displayed in the corresponding window. Remember, window itself is never replaced.

Q32. Define view object.
A. Views along with controls are used to provide visual representation of the app content. View is an object that draws content in a designated rectangular area and it responds to events within that area.

Q33. You wish to define your custom view. Which class will be subclassed?
A. Custom views can be defined by subclassing UIView.

Q34. Apart from incorporating views and controls, what else an app can incorporate?
A. Apart from incorporating views and controls, an app can also incorporate Core Animation layers into its view and control hierarchies.

Q35. What are layer objects and what do they represent?
A. Layer objects are data objects which represent visual content. Layer objects are used by views to render their content. Custom layer objects can also be added to the interface to implement complex animations and other types of sophisticated visual effects.


information copied from :


1.What is latest iOS version?

iOS – 7.1

2.What is latest Xcode version?

Xcode- 5.0

3.What is latest mac os version?

Mac OS X (10.9) -Maverics

4.What is iPad screen size?

non retina : 1024X768  , retina : 2048X1536

5.what is iPhone screen size?

iphones before iphone 5

non retina : 320X480  , retina : 640X960

after iphone 5

retina : 640X1136  

6.What are the features is IOS 6?

1.Map :beautifully designed from the ground up (and the sky down)

2.Integration of Facebook with iOS

3.shared photo streams.

4.Passbook – boarding passes, loyalty cards, retail coupons, cinema tickets and more all in one place

5.Facetime – on mobile network as wifi

6.changed Phone app – *remind me later,*reply with message.

7.Mail – redesigned more streamline interface.

8.Camera with panorama .

7.Who invented Objective c?

Broad cox and Tom Love

8.What is Cococa and cocoa touch?

Cocoa is for Mac App development  and cocoa touch is for apples touch devices – that provide all development environment

9.What is Objective c?

*Objective-C is a reflective, object-oriented programming language which adds Smalltalk-style messaging to the C programming language. strictly superset of c.

10. how declare methods in Objective c? and how to call them?

– (return_type)methodName:(data_type)parameter_name : (data_type)parameter_name

11. What is property in Objective c?

Property allow declared variables with specification like atomic/nonatmic, or retain/assign

12.What is meaning of “copy” keyword?

copy object during assignment and increases retain count by 1

13.What is meaning of “readOnly” keyword?

Declare read only object / declare only getter method

14.What is meaning of “retain” keyword?

Specifies that retain should be invoked on the object upon assignment. takes ownership of an object

15.What is meaning of “assign” keyword?

Specifies that the setter uses simple assignment. Uses on attribute of scalar type like float,int.

16.What is meaning of “atomic” keyword?

“atomic”, the synthesized setter/getter will ensure that a whole value is always returned from the getter or set by the setter, only single thread can access variable to get or set value at a time

17.What is meaning of “nonatomic” keyword?

In non atomic no such guaranty that value is returned from variable is same that setter sets. at same time

18.What is difference between “assign” and “retain” keyword?

Retain -Specifies that retain should be invoked on the object upon assignment. takes ownership of an object

Assign – Specifies that the setter uses simple assignment. Uses on attribute of scalar type like float,int.

19.What is meaning of “synthesize” keyword ?

ask the compiler to generate the setter and getter  methods according to the specification in the declaration

20.What is “Protocol” on objective c?

A protocol declares methods that can be implemented by any class. Protocols are not classes themselves. They simply define an interface that other objects are responsible for implementing. Protocols have many advantages. The idea is to provide a way for classes to share the same method and property declarations without inheriting them from a common ancestor

21.What is use of UIApplication class?

The UIApplication class implements the required behavior of an application.

22.What compilers apple using ?

The Apple compilers are based on the compilers of the GNU Compiler Collection.

23.What is synchronized() block in objective c? what is the use of that?

The @synchronized()directive locks a section of code for use by a single thread. Other threads are blocked until the thread exits the protected code.

24. What is the “interface” and “implementation”?

interface declares the behavior of class and implementation defines the behavior of class.

25.What is “private”, “Protected” and “Public” ?

private – limits the scope class variable to the class that declares it.

protected – Limits instance variable scope to declaring and inheriting classes.

public – Removes restrictions on the scope of instance variables

26. What is the use of “dynamic” keyword?

Instructs the compiler not to generate a warning if it cannot find implementations of accessor methods associated with the properties whose names follow.

27.What is “Delegate” ?

A delegate is an object that will respond to pre-chosen selectors (function calls) at some point in the future., need to implement the protocol method by the delegate object.

28.What is “notification”?

provides a mechanism for broadcasting information within a program, using notification we can send message to other object by adding observer .

29.What is difference between “protocol” and “delegate”?

protocol is used the declare a set of methods that a class that “adopts” (declares that it will use this protocol) will implement.

Delegates are a use of the language feature of protocols. The delegation design pattern is a way of designing your code to use protocols where necessary.

30.What is “Push Notification”?

to get the any update /alert from server .

31.How to deal with SQLite database?

Dealing with sqlite database in iOS:

1. Create database : sqlite3 AnimalDatabase.sql

2.Create table and insert data in to  table :

CREATE TABLE animals ( id INTEGER PRIMARY KEY, name VARCHAR(50), description TEXT, image VARCHAR(255) );

INSERT INTO animals (name, description, image) VALUES (‘Elephant’, ‘The elephant is a very large animal that lives in Africa and Asia’, ‘’);

3. Create new app –> Add SQLite framework and database file to project

4. Read the database and close it once work done with database :

// Setup the database object

sqlite3 *database;

// Init the animals Array

animals = [[NSMutableArray alloc] init];

// Open the database from the users filessytem

if(sqlite3_open([databasePath UTF8String], &database) == SQLITE_OK) {

// Setup the SQL Statement and compile it for faster access

const char *sqlStatement = “select * from animals”;

sqlite3_stmt *compiledStatement;

if(sqlite3_prepare_v2(database, sqlStatement, -1, &compiledStatement, NULL) == SQLITE_OK) {

// Loop through the results and add them to the feeds array

while(sqlite3_step(compiledStatement) == SQLITE_ROW) {

// Read the data from the result row

NSString *aName = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 1)];

NSString *aDescription = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 2)];

NSString *aImageUrl = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 3)];

// Create a new animal object with the data from the database

Animal *animal = [[Animal alloc] initWithName:aName description:aDescription url:aImageUrl];

// Add the animal object to the animals Array

[animals addObject:animal];

[animal release];



// Release the compiled statement from memory




32.What is storyboard? 

With Storyboards, all screens are stored in a single file. This gives you a conceptual overview of the visual representation for the app and shows you how the screens are connected. Xcode provides a built-in editor to layout the Storyboards.

  1. .storyboard is essentially one single file for all your screens in the app and it shows the flow of the screens. You can add segues/transitions between screens, this way. So, this minimizes the boilerplate  code required to manage multiple screens.
  2.   2.   Minimizes the overall no. of files in an app.

33.What is Category in Objective c?

A category allows you to add methods to an existing class—even to one for which you do not have the source.

34.What is block in objective c?

Blocks are a language-level feature added to C, Objective-C and C++, which allow you to create distinct segments of code that can be passed around to methods or functions as if they were values. Blocks are Objective-C objects, which means they can be added to collections like NSArray or NSDictionary. They also have the ability to capture values from the enclosing scope, making them similar to closures or lambdas in other programming languages.

35. How to parse xml? explain in deep.

Using NSXMLParser.  

Create xml parser object with xml data, set its delegate , and call the parse method with parserObject.

Delegate methods getting called :

– parserDidStartDocument:

– parserDidEndDocument:

– parser:didStartElement:namespaceURI:qualifiedName:attributes:

– parser:didEndElement:namespaceURI:qualifiedName:

– parser:didStartMappingPrefix:toURI:

– parser:didEndMappingPrefix:

– parser:resolveExternalEntityName:systemID:

– parser:parseErrorOccurred:

– parser:validationErrorOccurred:

– parser:foundCharacters:

– parser:foundIgnorableWhitespace:

– parser:foundProcessingInstructionWithTarget:data:

– parser:foundComment:

– parser:foundCDATA:

36.How to parse JSON? explain in deep.

By using NSJSONSerialization.

For example : NSArray *jsonArray = [NSJSONSerialization JSONObjectWithData: data options: NSJSONReadingMutableContainers error: &e];

37.How to use reusable cell in UITableview?

By using dequeReusableCellWithIdentifier

38.What is the meaning of “strong”keyword?

*strong -o “own” the object you are referencing with this property/variable. The compiler will take care that any object that you assign to this property will not be destroyed as long as you (or any other object) points  to it with a strong reference.

39.What is the meaning of “weak” keyword? 

*Weak – weak reference you signify that you don’t want to have control over the object’s lifetime. The object you are referencing weakly only lives on because at least one other object holds a strong reference to it. Once that is no longer the case, the object gets destroyed and your weak property will automatically get set to nil.

40.What is difference strong and  weak reference ? explain.

complier with be responsible for lifetime of object which is declared as strong. for weak object – compiler will destroy object once strong reference that hold weak object get destroyed.

41.What is ARC ? How it works? explain in deep.

Automatic reference counting (ARC)  If the compiler can recognize where you should be retaining and releasing objects, and put the retain and release statement in code.

42. What manual memory management ?  how it work?

In Manual memory management  developers is responsible for life cycle of object. developer has to retain /alloc and release the object wherever needed.

43. How to find the memory leaks in MRC?

By using –

1.  Static analyzer.

2. Instrument

44.what is use of NSOperation? how NSOperationque works?

An operation object is a single-shot object—that is, it executes its task once and cannot be used to execute it again. You typically execute operations by adding them to an operation queueAn NSOperationQueue object is a queue that handles objects of the NSOperation class type. An NSOperation object, simply phrased, represents a single task, including both the data and the code related to the task. The NSOperationQueue handles and manages the execution of all the NSOperation objects (the tasks) that have been added to it.

45.How to send crash report from device?

46.What is autorealease pool?

Every time -autorelease is sent to an object, it is added to the inner-most autorelease pool. When the pool is drained, it simply sends -release to all the objects in the pool.

Autorelease pools are simply a convenience that allows you to defer sending -release until “later”. That “later” can happen in several places, but the most common in Cocoa GUI apps is at the end of the current run loop cycle.

47.What happens when we invoke a method on a nil pointer?

48.Difference between nil and Nil.

Nil is meant for class pointers, and nil is meant for object pointers

49.What is fast enumeration?

for(id object in objets){


50. How to start a thread? 

– (void)performSelectorInBackground:(SEL)aSelector withObject:(id)arg on NSObject

NSThread* evtThread = [ [NSThread alloc] initWithTarget:self

selector:@selector( saySomething )

object:nil ];

[ evtThread start ];

51.How to download something from the internet?

By Using NSURLConnection , by starting connection or sending synchronous request.

52.what is synchronous web request and asynchronous ?

In  synchronous request main thread gets block and control will not get back to user till that request gets execute.

In Asynchronous control gets back to user even if request is getting execute.

53. Difference between sax parser and dom parser ?

SAX (Simple API for XML)

  1. Parses node by node
  2. Doesn’t store the XML in memory
  3. We can not 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

54.Explain stack and heap?

55.What are the ViewController  lifecycle in ios?

loadView – viewDidLoad-viewWillAppear-viewDidAppear – viewDisappear  – viewDidUnload

56.Difference between coredata & sqlite?

There is a huge difference between these two. SQLLite is a database itself like we have MS SQL Server. But CoreData is an ORM (Object Relational Model) which creates a layer between the database and the UI. It speeds-up the process of interaction as we dont have to write queries, just work with the ORM and let ORM handles the backend. For save or retrieval of large data, I recommend to use Core Data because of its abilities to handle the less processing speed of IPhone.

57.Steps for using coredata?

NSFetchedResultsController – It is designed primarily to function as a data source for aUITableView

58.Procedure to push the app in AppStore?

59.What are the Application lifecycle in ios?

ApplicationDidFinishLaunchingWithOption -ApplicationWillResignActive- ApplicationDidBecomeActive-ApplicationWillTerminate

60.Difference between release and autorelease ?

release – destroy the object from memory,

autorelease – destroy the object from memory in future when it is not in use.

61.How to start a selector on a background thread

– (void)performSelectorInBackground:(SEL)aSelector withObject:(id)arg on NSObject

62.What happens if the methods doesn’t exist

App will crash with exception unrecognized selector sent to instance.

63. How Push notification works?

Server – Apple server – device by using APNs


information copied from :


What is the MVC software architecture pattern?

  • What Most People Say: MVC is the pattern all well-written applications use.
  • What You Should Say: The Model-View-Controller pattern separates the internal representation of data from its display. The model is the internal representation of the data, while the view is how the data is presented to the user. The controller mediates between the two and also handles user interaction.
  • Why You Should Say It: “Candidates sound evasive when they don’t explain what MVC is or how it’s used,” says Schweitzer. “An incomplete answer makes it seem like you don’t understand the purpose of MVC software architecture patterns.”

What is a delegate?

  • What Most People Say: Delegates are used in UITableView to get the data for the table.
  • What You Should Say: Delegates are Apple’s way of implementing call back methods. They allow a class to send information to a different class.
  • Why You Should Say It: “Again, a short answer doesn’t inspire confidence,” Schweitzer explains. “You need to show that you understand the purpose of delegates and how they fit into the architecture of the application without pontificating. The key is to supply just enough information to demonstrate your understanding of a concept or function, then get off the stage.”

What is the difference between a delegate and an NSNotification?

  • What Most People Say: They are different ways of accomplishing the same thing. They are completely different and are used in different ways.
  • What You Should Say: Delegates and NSNotifications can be used to accomplish nearly the same functionality. However, delegates are one-to-one while NSNotifications are one-to-many.
  • Why You Should Say It: Developers who don’t know the answer to a technical question often resort to double speak, which never works. Instead, demonstrate your experience with delegates and NSNotifications by explaining how they’re used and the advantages and disadvantages of each.

What is a block and how is it used?

  • What Most People Say: A block is a function.
  • What You Should Say: A block is a chunk of code that can be passed to a method. The code is executed based on what happens in the method. Apple is moving many of the iOS APIs toward blocks.
  • Why You Should Say It: First and foremost, “a block is not a function,” observes Schweitzer. “The second answer is not only accurate, it shows that you’re following the trends, which is critical for a developer.”

What’s the difference between a xib and a storyboard?

  • What Most People Say: They’re the same thing.
  • What You Should Say: Both are used in Xcode to layout screens (view controllers). A xib defines a single view controller screen, while a storyboard shows many view controllers and also shows the relationship between them. Apple is encouraging developers to use storyboards for all their applications.
  • Why You Should Say It: “The interviewer isn’t trying to trick you,” says Schweitzer. “Storyboards and xib files are similar but they’re not exactly the same. He wants you to differentiate the two and explain their advantages and disadvantages.”

What is CoreData?

  • What Most People Say: CoreData is Apple’s way of storing data on the disk.
  • What You Should Say: CoreData is an SQLite database API. By setting up CoreData properly, an application can store and retrieve the internal state of a class rapidly.
  • Why You Should Say It: Incorporating details into your answers demonstrates your understanding of the concept and inspires confidence.

Describe Waterfall and Agile methodologies.

  • What Most People Say: Waterfall is the older methodology that is not used in modern software development.
  • What You Should Say: Books have been written about this. Briefly, in Waterfall the requirements are defined without much or any interaction with the software development team. In Agile, there is continuous refining of requirements as development proceeds due to constant interaction between those defining the requirements and the people doing the development.
  • Why You Should Say It: Waterfall is older but it’s still used and the interviewer didn’t ask you to rate the two, Schweitzer says. You should explain the differences between the two methodologies, then invite an in-depth conversation by explaining when each is most effective and describing your experience with each one.


information copied from :


*Q: How would you create your own custom view?

A:By Subclassing the UIView class.

*Q: What is App Bundle?

A:When you build your iOS app, Xcode packages it as a bundle. A bundle is a directory in the file system that groups related resources together in one place. An iOS app bundle contains the app executable file and supporting resource files such as app icons, image files, and localized content.

*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  NSArray and  NSMutableArray?

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

*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 objectʼs retain count is reduced to 0, it is deallocated.

This will explain how the memory management is done in iOS

This will explain how the memory management is done in iOS

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

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


What are the App states. Explain them?


  • Not running State:  The app has not been launched or was running but was terminated by the system.
  • Inactive state: The app is running in the foreground but is currently not receiving events. (It may be executing other code though.) An app usually stays in this state only briefly as it transitions to a different state. The only time it stays inactive for any period of time is when the user locks the screen or the system prompts the user to respond to some event, such as an incoming phone call or SMS message.
  • Active state: The app is running in the foreground and is receiving events. This is the normal mode for foreground apps.
  • Background state:  The app is in the background and executing code. Most apps enter this state briefly on their way to being suspended. However, an app that requests extra execution time may remain in this state for a period of time. In addition, an app being launched directly into the background enters this state instead of the inactive state. For information about how to execute code while in the background, see “Background Execution and Multitasking.”
  • Suspended state:The app is in the background but is not executing code. The system moves apps to this state automatically and does not notify them before doing so. While suspended, an app remains in memory but does not execute any code. When a low-memory condition occurs, the system may purge suspended apps without notice to make more space for the foreground app.

*Q: Explain how the push notification works.



*Q: Explain the steps involved in submitting the App to App-Store.


image: ../Art/administration_tasks.png

Apple provides the tools you need to develop, test, and submit your iOS app to the App Store. To run an app on a device, the device needs to be provisioned for development, and later provisioned for testing. You also need to provide information about your app that the App Store displays to customers and upload screenshots. Then you submit the app to Apple for approval. After the app is approved, you set a date the app should appear in the App Store as well as its price. Finally, you use Apple’s tools to monitor the sales of the app, customer reviews, and crash reports. Then you repeat the entire process again to submit updates to your app.

Ref: App Store Review Guidelines

*Q: Why do we need to use @Synthesize?


We can use generated code like nonatomic, atmoic, retain without writing any lines of code. We also have getter and setter methods. To use this, you have 2 other ways: @synthesize or @dynamic: @synthesize, compiler will generate the getter and setter automatically for you, @dynamic: you have to write them yourself.@property is really good for memory management, for example: retain.How can you do retain without @property? 

if (_variable != object)


    [_variable release];

    _variable = nil;

    _variable = [object retain];


How can you use it with @property?self.variable = object; When we are calling the above line, we actually call the setter like [self setVariable:object] and then the generated setter will do its job.

*Q: Multitasking support is available from which version?


iOS 4.0.

*Q: How many bytes we can send to apple push notification server?



*Q: Can you just explain about memory management in iOS?


Refer: iOS Memory Management

*Q: What is code signing?


Signing an application allows the system to identify who signed the application and to verify that the application has not been modified since it was signed. Signing is a requirement for submitting to the App Store (both for iOS and Mac apps). OS X and iOS verify the signature of applications downloaded from the App Store to ensure that they they do not run applications with invalid signatures. This lets users trust that the application was signed by an Apple source and hasn’t been modified since it was signed.

Xcode uses your digital identity to sign your application during the build process. This digital identity consists of a public-private key pair and a certificate. The private key is used by cryptographic functions to generate the signature. The certificate is issued by Apple; it contains the public key and identifies you as the owner of the key pair.

In order to sign applications, you must have both parts of your digital identity installed. Use Xcode or Keychain Access to manage your digital identities. Depending on your role in your development team, you may have multiple digital identities for use in different contexts. For example, the identity you use for signing during development is different from the identity you user for distribution on the App Store. Different digital identities are also used for development on OS X and on iOS.

An application’s executable code is protected by its signature because the signature becomes invalid if any of the executable code in the application bundle changes. Resources such as images and nib files are not signed; a change to these files does not invalidate the signature.

An application’s signature can be removed, and the application can be re-signed using another digital identity. For example, Apple re-signs all applications sold on the App Store. Also, a fully-tested development build of your application can be re-signed for submission to the App Store. Thus the signature is best understood not as indelible proof of the application’s origins but as a verifiable mark placed by the signer 

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


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?


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.


Create them as properties in the header that are retained. In the viewDidUnload set the outlets to nil(i.eself.outlet = nil). Finally in dealloc make sure to release the outlet.

iOS interview Questions for  Expert level

*Q:What is sandbox?


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?


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];


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.


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.


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.





return self;









{ // 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?


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

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


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];  


 *Q: What is Controller Object?


A controller object acts as a coordinator or as an intermediary between one or more view objects and one or more model objects. In the Model-View-Controller design pattern, a controller object (or, simply, acontroller) interprets user actions and intentions made in view objects—such as when the user taps or clicks a button or enters text in a text field—and communicates new or changed data to the model objects.image: Art/controller_object.jpg

When model objects change—for example, the user opens a document stored in the file system—it communicates that new model data to the view objects so that they can display it. Controllers are thus the conduit through which view objects learn about changes in model objects and vice versa. Controller objects can also set up and coordinate tasks for an application and manage the life cycles of other objects. The Cocoa frameworks offer three main controller types: coordinating controllers, view controllers (on iOS), and mediating controllers (on OS X).

*Q: What is Wildcard App IDs?


A wildcard app ID allows you to use an app ID to match multiple apps; wildcard app IDs are useful when you first start developing new apps because you don’t need to create a separate app ID for each app. However, wildcard app IDs can’t be used to provision an app that uses APNS, In App Purchase, or Game Center.

A wildcard app ID omits some or all of the bundle ID in the search string and replaces that portion with an asterisk character (*). The asterisk must always appear as the last character in the bundle search string.

When you use a wildcard app ID, characters preceding the asterisk (if any) must match the characters in the bundle ID, exactly as they would for an explicit app ID. The asterisk matches all remaining characters in the bundle ID. Further, the asterisk must match at least one character in the bundle ID. This table shows an example search string and how it matches some bundle IDs but not others.

image: Art/app_ids_examples.jpg

If an app id uses an * as the bundle ID, then the search string matches any bundle ID.

*Q: What is categories in iOS?


We use categories to define additional methods of an existing class—even one whose source code is unavailable to you—without subclassing. You typically use a category to add methods to an existing class, such as one defined in the Cocoa frameworks. The added methods are inherited by subclasses and are indistinguishable at runtime from the original methods of the class. You can also use categories of your own classes to:

  • Distribute the implementation of your own classes into separate source files—for example, you could group the methods of a large class into several categories and put each category in a different file.
  • Declare private methods.

You add methods to a class by declaring them in an interface file under a category name and defining them in an implementation file under the same name. The category name indicates that the methods are an extension to a class declared elsewhere, not a new class.

Refer: Categories and Extensions

*Q: What is Delegation in iOS?


Delegation is a design pattern in which one object sends messages to another object—specified as its delegate—to ask for input or to notify it that an event is occurring. Delegation is often used as an alternative to class inheritance to extend the functionality of reusable objects. For example, before a window changes size, it asks its delegate whether the new size is ok. The delegate replies to the window, telling it that the suggested size is acceptable or suggesting a better size. (For more details on window resizing, see the windowWillResize:toSize: message.)

Delegate methods are typically grouped into a protocol. A protocol is basically just a list of methods. The delegate protocol specifies all the messages an object might send to its delegate. If a class conforms to (or adopts) a protocol, it guarantees that it implements the required methods of a protocol. (Protocols may also include optional methods).In this application, the application object tells its delegate that the main startup routines have finished by sending it the applicationDidFinishLaunching: message. The delegate is then able to perform additional tasks if it wants.

*Q: How can we achieve singleton pattern in iOS?


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.

Several Cocoa framework classes are singletons.

They include NSFileManagerNSWorkspaceNSApplication, and, in UIKit, UIApplication. A process is limited to one instance of these classes. When a client asks the class for an instance, it gets a shared instance, which is lazily created upon the first request.Refer: Singleton Pattren

*Q: What is delegate pattern in iOS?


Delegation is a mechanism by which a host object embeds a weak reference (weak in the sense that it’s a simple pointer reference, unretained) to another object—its delegate—and periodically sends messages to the delegate when it requires its input for a task. The host object is generally an “off-the-shelf” framework object (such as an NSWindow or NSXMLParserobject) that is seeking to accomplish something, but can only do so in a generic fashion. The delegate, which is almost always an instance of a custom class, acts in coordination with the host object, supplying program-specific behavior at certain points in the task (see Figure 4-3). Thus delegation makes it possible to modify or extend the behavior of another object without the need for subclassing.

*Q: What are all the difference between categories and subclasses? Why should we go to subclasses?


Category is a feature of the Objective-C language that enables you to add methods (interface and implementation) to a class without having to make a subclass. There is no runtime difference—within the scope of your program—between the original methods of the class and the methods added by the category. The methods in the category become part of the class type and are inherited by all the class’ssubclasses.As with delegation, categories are not a strict adaptation of the Decorator pattern, fulfilling the intent but taking a different path to implementing that intent. The behavior added by categories is a compile-time artifact, and is not something dynamically acquired. Moreover, categories do not encapsulate an instance of the class being extended.The Cocoa frameworks define numerous categories, most of them informal protocols . Often they use categories to group related methods. You may implement categories in your code to extend classes without subclassing or to group related methods. However, you should be aware of these caveats:

  • You cannot add instance variables to the class.
  • If you override existing methods of the class, your application may behave unpredictably.

*Q: What is notification in iOS?


The notification mechanism of Cocoa implements one-to-many broadcast of messages based on the Observer pattern. Objects in a program add themselves or other objects to a list of observers of one or more notifications, each of which is identified by a global string (the notification name). The object that wants to notify other objects—the observed object—creates a notification object and posts it to a notification center. The notification center determines the observers of a particular notification and sends the notification to them via a message. The methods invoked by the notification message must conform to a certain single-parameter signature. The parameter of the method is the notification object, which contains the notification name, the observed object, and a dictionary containing any supplementalinformation.Posting a notification is a synchronous procedure. The posting object doesn’t regain control until the notification center has broadcast the notification to all observers. For asynchronous behavior, you can put the notification in a notification queue; control returns immediately to the posting object and the notification center broadcasts the notification when it reaches the top of the queue.Regularnotifications—that is, those broadcast by the notification center—are intraprocess only. If you want to broadcast notifications to other processes, you can use the istributed notification center and its related API.

*Q:What is the difference between delegates and notifications?


We can use notifications for a variety of reasons. For example, you could broadcast a notification to change how user-interface elements display information based on a certain event elsewhere in the program. Or you could use notifications as a way to ensure that objects in a document save their state before the document window is closed. The general purpose of notifications is to inform other objects of program events so they can respond appropriately.But objects receiving notifications can react only after the event has occurred. This is a significant difference from delegation. The delegate is given a chance to reject or modify the operation proposed by the delegating object. Observing objects, on the other hand, cannot directly affect an impending operation.

*Q:What is posing in iOS?


Objective-C permits a class to entirely replace another class within an application. The replacing class is said to “pose as” the target class. All messages sent to the target class are then instead received by the posing class. There are some restrictions on which classes can pose:
  • A class may only pose as one of its direct or indirect superclasses
  • The posing class must not define any new instance variables which are absent from the target class (though it may define or override methods).
  • No messages must have been sent to the target class prior to the posing.
Posing, similarly to categories, allows globally augmenting existing classes. Posing permits two features absent from categories:
  • A posing class can call overridden methods through super, thus incorporating the implementation of the target class.
  • A posing class can override methods defined in categories.

*Q:What is atomic and nonatomic? Which one is safer? Which one is default?


You can use this attribute to specify that accessor methods are not atomic. (There is no keyword to denote atomic.)

Specifies that accessors are nonatomic. By default, accessors are atomic.

Properties are atomic by default so that synthesized accessors provide robust access to properties in a multithreaded environment—that is, the value returned from the getter or set via the setter is always fully retrieved or set regardless of what other threads are executing concurrently.

If you specify strongcopy, or retain and do not specify nontoxic, then in a reference-counted environment, a synthesized get accessor for an object property uses a lock and retains and autoreleases the returned value—the implementation will be similar to the following:

[_internal lock]; // lock using an object-level lock
id result = [[value retain] autorelease];
[_internal unlock];
return result;

If you specify nonatomic, a synthesized accessor for an object property simply returns the value directly.

Markup and Deprecation

Properties support the full range of C-style decorators. Properties can be deprecated and support __attribute__ style markup:

@property CGFloat x
@property CGFloat y __attribute__((…));

*Q: What is run loop in iOS ?


Run loops are part of the fundamental infrastructure associated with threads. A run loop is an event processing loop that you use to schedule work and coordinate the receipt of incoming events. The purpose of a run loop is to keep your thread busy when there is work to do and put your thread to sleep when there is none.

Run loop management is not entirely automatic. You must still design your thread’s code to start the run loop at appropriate times and respond to incoming events. Both Cocoa and Core Foundation provide run loop objects to help you configure and manage your thread’s run loop. Your application does not need to create these objects explicitly; each thread, including the application’s main thread, has an associated run loop object. Only secondary threads need to run their run loop explicitly, however. In both Carbon and Cocoa applications, the main thread automatically sets up and runs its run loop as part of the general application startup process.

*Q: What isDynamic typing?


A variable is dynamically typed when the type of the object it points to is not checked at compile time. Objective-C uses the id data type to represent a variable that is an object without specifying what sort of object it is. This is referred to as dynamic typing.

Dynamic typing contrasts with static typing, in which the system explicitly identifies the class to which an object belongs at compile time. Static type checking at compile time may ensure stricter data integrity, but in exchange for that integrity, dynamic typing gives your program much greater flexibility. And through object introspection (for example, asking a dynamically typed, anonymous object what its class is), you can still verify the type of an object at runtime and thus validate its suitability for a particular operation.

*Q: What is push notification?How it works?


Refer apple documentation

*Q: What is the configuration file name in iOS explain in brief ? (Or) What is plist file and explain about it is usage?


A property list is a representation of a hierarchy of objects that can be stored in the file system and reconstituted later. Property lists give applications a lightweight and portable way to store small amounts of data. They are hierarchies of data made from specific types of objects—they are, in effect, an object graph. Property lists are easy to create programmatically and are even easier to serialize into a representation that is persistent. Applications can later read the static representation back into memory and recreate the original hierarchy of objects. Both Cocoa Foundation and Core Foundation have APIs related to property list serialization and deserialization.

Property List Types and Objects

Property lists consist only of certain types of data: dictionaries, arrays, strings, numbers (integer and float), dates, binary data, and Boolean values. Dictionaries and arrays are special types because they are collections; they can contain one or multiple data types, including other dictionaries and arrays. This hierarchical nesting of objects creates a graph of objects. The abstract data types have corresponding Foundation classes, Core Foundation types, and XML elements for collection objects and value objects.

 *Q:When will be the autorelease object released?


Once the pool recives drain message.

*Q:Consider we are implementing our own thread with lot of autoreleased object. Is it mandatory to use autorelease pool on this scenario if yes/no why?



 *Q:  Have you ever used automated unit test framework in iOS? Explain in short?


*Q: What are all the difference between iOS3, iOS4 and iOS5?


Refer:  Apple iOS Versions and diffrences

*Q: Is there any garbage collector concept available in iOS?


No, Manual memory management or ARC.

 *Q: What is difference between synchronous and asynchronous in web request?


*Q:What are all the instruments available in Xcode?


*Q:What is the difference between copy & retain? When can we go for copy and when can we go for retain?



information copied from :



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.

Difference between categories and extensions?

Ans:Class extensions are similar to categories. The main difference is that with an extension, the compiler will expect you to implement the methods within your main @implementation, whereas with a category you have a separate @implementation block. So you should pretty much only use an extension at the top of your main .m file (the only place you should care about ivars, incidentally) — it’s meant to be just that, an extension.

Difference between protocol in objective c and interfaces in java?

Ans:Protocol is also way to relate classes that are not related in inheritance hierarchy. Protocols and interfaces both are used to achieve multiple inheritance.

There is minor difference between these two. In Objective-C, protocols also implement NSObject protocol to access all the mehthods in NSObject

@protocol WebProtocol <NSObject>


If I don’t implement NSObject explicitly, I will not be able to access NSObject methods like retain, release etc. when I access through WebProtocol instance.

While in Java you don’t need to implement Object interface explicitly. It is implicitly implemented.

This link will help you. Thanks to Tom Jefferys.

What are KVO and KVC?

KVC: Normally instance variables are accessed through properties or accessors but KVC gives another way to access variables in form of strings. In this way your class acts like a dictionary and your property name for example “age” becomes key and value that property holds becomes value for that key. For example, you have employee class with name property.

You access property like

NSString age = emp.age;

setting property value.

emp.age = @”20″;

Now how KVC works is like this

[emp valueForKey:@”age”];

[emp setValue:@”25″ forKey:@”age”];

KVO : The mechanism through which objects are notified when there is change in any of property is called KVO.

For example, person object is interested in getting notification when accountBalance property is changed in BankAccount object.To achieve this, Person Object must register as an observer of the BankAccount’s accountBalance property by sending an addObserver:forKeyPath:options:context: message.

Can we use two tableview controllers on one view controller?

Ans: Yes, we can use two tableviews on the same view controllers and you can differentiate between two by assigning them tags…or you can also check them by comparing their memory addresses.

What is keyword atomic in Objective C?

Ans: When you place keyword atomic with a property, it means at one time only one thread can access it.

What are mutable and immutable types in Objective C?

Ans: Mutable means you can change its contents later but when you mark any object immutable, it means once they are initialized, their values cannot be changed. For example, NSArray, NSString values cannot be changed after initialized.

When we call objective c is runtime language what does it mean?

Ans: Objective-C runtime is runtime library that is open source that you can download and understand how it works. This library is written in C and adds object-oriented capabilities to C and makes it objective-c. It is only because of objective c runtime that it is legal to send messages to objects to which they don’t know how to respond to. Methods are not bound to implementation until runtime. Objective-C defers its decisions from compile time to run time as much as it can. For example, at runtime, it can decide to which object it will send message or function.

What is difference between NSNotification and delegate?

Ans:Delegate is passing message from one object to other object. It is like one to one communication while nsnotification is like passing message to multiple objects at the same time. All other objects that have subscribed to that notification or acting observers to that notification can or can’t respond to that event. Notifications are easier but you can get into trouble by using those like bad architecture. Delegates are more frequently used and are used with help of protocols.

Swap the two variable values without taking third variable?


int x=10;
int y=5;
NSLog(@”x==> %d”,x);

NSLog(@”Y Value==> %d”,y);

NSLog(@”x Value==> %d”,x);

Thanks to Subrat for answering this question.

What is push notification?

Imagine, you are looking for a job. You go to software company daily and ask sir “is there any job for me” and they keep on saying no.  Your time and money is wasted on each trip.(Pull Request mechanism)

So, one day owner says, if there is any suitable job for you, I will let you know. In this mechanism, your time and money is not wasted. (Push Mechanism)

How it works?

This service is provided by Apple in which rather than pinging server after specific interval for data which is also called pull mechanism, server will send notification to your device that there is new piece of information for you. Request is initiated by server not the device or client.

Flow of push notification

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?

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.

What is responder chain?

Ans: Suppose you have a hierarchy of views such like  there is superview A which have subview B and B has a subview C. Now you touch on inner most view C. The system will send touch event to subview C for handling this event. If C View does not want to handle this event, this event will be passed to its superview B (next responder). If B also does not want to handle this touch event it will pass on to superview A. All the view which can respond to touch events are called responder chain. A view can also pass its events to uiviewcontroller. If view controller also does not want to respond to touch event, it is passed to application object which discards this event.

Apple responder chain

Apple responder chain

 Can we use two tableview controllers on one view controller?

Ans:Yes. We can use as many table views in one view controllers. To differentiate between tableviews, we can assign table views different tags.

Can we use one tableview with two different datasources? How you will achieve this?

Ans:Yes. We can conditionally bind tableviews with two different data sources.

When to use NSMutableArray and when to use NSArray?

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 many autorelease pool you can create in your application? Is there any limit?If we don’t create any autorelease pool in our application then is there any autorelease pool already provided to us?

There is no limit for creating autorelease pools in your application. If you dont create an autorelease pool, there is one autorelease automatically created in your application in main.m file.

When you will create an auto release pool in your application?

There are different occasions when you need to create autorelease pool in your application.
1. When you create a new thread you need to create an autorelease pool because each thread manages his own memory. Also, if one thread creates a problem, it will be only inside that thread, not in main thread.

2. When you write a loop that creates lot of temporary objects, then you should create an autorelease pool. Take a look at following code

NSMutableArray *array = [NSMutableArray arrayWithArray:anyOtherArray];

If this is only one line, no problem because array is added to application main autorelease pool and it will be eventaully released from memory but imagine if you are in loop which runs one thousad times then there will lots of temp objects added to application main autorelease pool which is kind of bad memory management practice. To fix this

for (int i=0; i<1000, i++) {
NSAutoreleasePool *pool = [NSAutoreleasePool new];
NSMutableArray *array = [NSMutableArray arrayWithArray:anyOtherArray];
[pool release];


Now array object is being added to this “pool” rahter than application main autorelease pool and this pool is being release at each iteration of loop. If we have not created this pool these 1000 array objects will reside in memory untill application main autorelease pool is drained.

What happens when you send autorelease or retain message to autorelease pool.

NSAutoreleasePool  *autoRelease =[ [[ NSAutoreleasePool alloc] init] autorelease]; or

NSAutoreleasePool  *autoRelease =[ [[ NSAutoreleasePool alloc] init] retain];

An exception is raised.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s