Monday, 12 May 2014

View controller and View delegate method (what and why)

1) loadView- Only called when view controller is created and only when done programitcally. Bounds are incorrect (normally empty) at this point.

2) viewDidLoad - Only called when view controller is created. Bounds are incorrect (normally empty) at this point.

3) viewWillAppear - Called whenever the view is presented on screen 

4 )viewWillLayoutSubviews - This is the first method where we have the correct bounds for the device and is called whenever the view controller is changing the display of the view (like device orientation, view loaded) or the UIView is marked as needing a layout

5) layoutSubviews - This method is called on the UIView rather than the UIViewController. It has the correct bounds. Great place to change layout.

6)viewDidLayoutSubviews - Called after layoutSubviews is called on UIView. Changes made in layoutSubviews can be animated, further changes made in this method can cancel the animations.


7) viewDidAppear - Called once the view has appeared. It has the correct bounds but changes called here can happen after an animation has occurred and cause a slight jump.

Sunday, 11 May 2014

Memory related question and Answer

1) Copy 
 =>It creates a new object and when new object is created retain count will be 1.
 =>Copy will copy the data present in the memory location and will assign it to the variable so in the case of copy you are first copying the data from a location assign it to the variable which increases the retain count.
=>Copy works on value only 
=>Copying an object, however you do it, should create another object with duplicate values. Think of this as a clone. You do NOT share the clone with whomever passed it to you.

2 )Retain
=> It is done on the created object, and it just increase the reference count of an object.
=>Retain copies the reference (address) and increases the retain count and you have to take care of releasing that object.
=> Increases the retainCount of the receiver. An object is removed from memory - deadlocked, when retainCount is 0.
=>Retaining an object will increase its retain count by one. This will help keep the object in memory and prevent it from being blown away. What this means is that if you only hold a retained version of it, you share that copy with whomever passed it to you.

3) Release
   =>Relese  decreases the reference on an object
4)Dreain
 =>Drain is used in place of release on ONLY for NSAutoreleasePool objects due to some arcana related to the Objective C garbage collection

5) Dealloc
    =>Dealloc is called by the system once the retainCount of an object hits 0. It is where you clean up various things your object has (like a deconstructor or finalizer). You should NEVER call it directly, except for calling [super dealloc] at the end of your dealloc routines.

Wednesday, 9 April 2014

What is Extension

A class extension bears some similarity to a category, but it can only be added to a class for which you have the source code at compile time (the class is compiled at the same time as the class extension).
Extensions are actually categories without the category name. It's often referred as anonymous categories.
An extension cannot be declared for any class, only for the classes that we have original implementation of source code.
An extension is adding private methods and private variables that are only specific to the class.
Any method or variable declared inside the extensions is not accessible even to the inherited classes.

What is Block in objective c

Blocks are Objective-C’s anonymous functions. They let you pass arbitrary statements between objects as you would data, which is often more intuitive than referencing functions defined elsewhere. In addition, blocks are implemented as closures, making it trivial to capture the surrounding state

What is Polymorphism

=>Polymorphism is one of the principle of object oriented programming. "Poly" means many and "morph" means forms hence the name polymorphism.
=>Polymorphism also refered to as one name many forms or having one name with multiple functionality.
=>Use same method name with different signature or same signature but in different class.So depending on a data type it processes objects differently and an ability to redefine methods for a derived classes.

What is Abstraction ?

=> Abstraction is the act of representing essential features without including the background details or explanations. 
 => In the computer science and software engineering domain, the abstraction principle is used to reduce complexity and allow efficient design and implementation of complex software systems.

List the five iOS app states.

1) Not running -: The app has not been launched or was running but was terminated by the system.
2) Inactive -: The app is running in the foreground, but not receiving events. An iOS app can be placed into an inactive state, for example, when a call or SMS message is received.
3) Active -: The app is running in the foreground, and receiving events.
4) Background -: The app is running in the background, and executing code.
5 )Suspended -: The app is in the background, but no code is being executed