Category Archives: BitCode

How to carry an Object through an Intent to the Next Activity in Android Using “Parcelable” interface

How to carry an Object through an Intent to the Next Activity in Android Using “Parcelable” interface

Download the Sample Demo of this app here ParcelableDemo.

We all know that we carry data from one activity to another activity using Intents in Android. We put the data into the intent as extra data in the form of key value pair. And the targeted activity will call its method “getIntent()” to get the intent because of which that activity started and then we can get the data in the form of a Bundle object by call getExtras() method on that intent.

 

However we can not directly carry an object through an Intent by putting it as extra data.

 

An Intent can contain objects of only those classes which are implementing “Parcelable” interface or “Serializable” interface.

Here we will be talking about the “Parcelable” interface.

 

In this example we have created a class UserInfo,which will be holding the information about the user i.e. UserName and UserID.

 

We would like to put an Object of UserInfo as extra data and receive into another activity which will be activated by the Intent.
To be able to put UserInfo object into the Intent object, the UserInfo class must implement Parcelable interface.

UserInfo.java

package in.bitcode.parcelabledemo;import android.os.Parcel;
import android.os.Parcelable;

public class UserInfo implements Parcelable {

private String userName;
private int userID;

public static final Parcelable.Creator<UserInfo> CREATOR = new UserInfoCreatorFromParcel();

public UserInfo(String userName, int userID) {
this.userName = userName;
this.userID = userID;
}

public int getUserID() {
return userID;
}

public String getUserName() {
return userName;
}

@Override
public int describeContents() {
return 0;
}

@Overrid
public void writeToParcel(Parcel dest, int flags) {
dest.writeString(userName);
dest.writeInt(userID);
}

private static class UserInfoCreatorFromParcel implements Parcelable.Creator<UserInfo> {

@Override
public UserInfo createFromParcel(Parcel source) {
return new UserInfo( source.readString(), source.readInt() );
}

@Override
public UserInfo[] newArray(int size) {
return null;
}

}

}

 

When an Object of UserInfo is added to intent by using putExtra method of intent, UserInfo objects writeToParcel method is called.

 

Intent intent = new Intent( this, UserAct.class );
intent.putExtra( “userinfo”, new UserInfo( “TestUserName”, 100 ) );

writeToParcel( Parcel dest, int flag ) method will accept following arguments dest of type Parcel and flag of type int.

dest: It is the Parcel to which the data of the UserInfo object must be written.
Flag: It is the int flag indicating how the data must be written to the Parcel.

To make sure that you are able to read back the UserInfo object, the UserInfo class must have a public static member “CREATOR” of type Parcelable.Creator<YourClass>. ( In this case YourClass must be replaced with UserInfo).

Following is the member method of Creator interface

public YourClass createFromParcel(Parcel in) {
//create an object of YourClass  and fill in the data by reading it
//from the Parcel

return new YourClass();
}

 

This method is called when you read the YouClass object back from the Intent.

To get the same object from the intent, you need to call the Intents getParcelableExtra method with the matching key.

UserInfo userInfo = intent.getParcelableExtra(“userinfo”);

Following Demo demonstrates the user of Parcelable

 

Activity_main.xml

 

<LinearLayout xmlns:android=“http://schemas.android.com/apk/res/android”xmlns:tools=“http://schemas.android.com/tools”

android:layout_width=“match_parent”

android:layout_height=“match_parent”

android:orientation=“vertical” >

 

<LinearLayout

android:layout_width=“match_parent”

android:layout_height=“wrap_content”

android:layout_marginLeft=“10dip”

android:layout_marginRight=“10dip”

android:layout_marginTop=“10dip”

android:gravity=“center_vertical” >

 

<ImageView

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

android:src=“@drawable/bitcode” />

 

<TextView

android:id=“@+id/textView1″

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

android:layout_marginLeft=“30dip”

android:text=“Parcelable Demo”

android:textAppearance=“?android:attr/textAppearanceLarge” />

</LinearLayout>

 

<EditText

android:id=“@+id/edtUserID”

android:layout_width=“match_parent”

android:layout_height=“wrap_content”

android:hint=“User ID”

android:inputType=“numberDecimal” >

 

<requestFocus />

</EditText>

 

<EditText

android:id=“@+id/edtUserName”

android:layout_width=“match_parent”

android:layout_height=“wrap_content” />

 

<Button

android:id=“@+id/btnNext”

android:layout_width=“match_parent”

android:layout_height=“wrap_content”

android:text=“Write to Parcel and Start Next Activity” />

 

</LinearLayout>

 

 

MainActivity.Java

 

package in.bitcode.parcelabledemo; 

import android.os.Bundle;

import android.app.Activity;

import android.content.Intent;

import android.view.Menu;

import android.view.View;

import android.widget.Button;

import android.widget.EditText;

 

public class MainActivity extends Activity {

 

private EditText edtUserName, edtUserID;

private Button btnNext;

 

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

 

setContentView(R.layout.activity_main);

 

init();

 

btnNext.setOnClickListener(new View.OnClickListener() {

 

@Override

public void onClick(View v) {

Intent intent = new Intent(MainActivity.this, UserAct.class);

 

String userName = edtUserName.getText().toString();

int userID = Integer.parseInt(edtUserID.getText().toString());

 

intent.putExtra(“userinfo”, new UserInfo(userName, userID));

 

startActivity(intent);

}

});

 

}

 

private void init() {

edtUserName = (EditText) findViewById(R.id.edtUserName);

edtUserID = (EditText) findViewById(R.id.edtUserID);

btnNext = (Button) findViewById(R.id.btnNext);

}

 

}

 

 

 

activity_useract.xml

 

 

<LinearLayout xmlns:android=“http://schemas.android.com/apk/res/android”xmlns:tools=“http://schemas.android.com/tools”

android:layout_width=“match_parent”

android:layout_height=“match_parent”

android:orientation=“vertical” >

 

<LinearLayout

android:layout_width=“match_parent”

android:layout_height=“wrap_content”

android:layout_marginLeft=“10dip”

android:layout_marginRight=“10dip”

android:layout_marginTop=“10dip”

android:gravity=“center_vertical” >

 

<ImageView

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

android:src=“@drawable/bitcode” />

 

<TextView

android:id=“@+id/textView1″

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

android:layout_marginLeft=“30dip”

android:text=“Parcelable Demo”

android:textAppearance=“?android:attr/textAppearanceLarge” />

</LinearLayout>

 

<TextView

android:id=“@+id/txtUserID”

android:layout_width=“match_parent”

android:layout_height=“wrap_content”

android:layout_marginTop=“10dip”

android:textSize=“20sp” />

 

<TextView

android:id=“@+id/txtUserName”

android:layout_width=“match_parent”

android:layout_height=“wrap_content”

android:layout_marginTop=“10dip”

android:textSize=“20sp” />

 

</LinearLayout>

 

 

UserAct.java

 

package in.bitcode.parcelabledemo; 

import android.app.Activity;

import android.content.Intent;

import android.os.Bundle;

import android.widget.TextView;

 

public class UserAct extends Activity {

 

private TextView txtUserName, txtUserID;

 

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

 

init();

 

}

 

private void init() {

txtUserName = (TextView) findViewById(R.id.txtUserName);

txtUserID = (TextView) findViewById(R.id.txtUserID);

 

Intent intent = getIntent();

UserInfo userInfo = intent.getParcelableExtra(“userinfo”);

 

txtUserID.setText(“User ID: ” + userInfo.getUserID());

txtUserName.setText(userInfo.getUserName());

}

 

}

 

 

Download the Sample Demo of this app here ParcelableDemo.

 

iPhone Interview Questions

Hi All , find below the interview questions for iPhone programming. I have collected these from different resources . Some of them might be duplicated as well. These covers a lot questions that you can use to prepare for iPhone interview. If you have any comments then please add those in comments section at the bottom.

 

Apple History , Apple Applications and iOS

Q What are all  the newly added frameworks iOS 4.3 to iOS 5.0 ?
Ans : Accounts
CoreBluetooth
CoreImage
GLKit
GSS
NewsstandKit
Twitter
SocialKit

Q: Multitasking support is available from which version?
A: iOS 4.0.

Q: How many bytes we can send to apple push notification server?
A: 256bytes.

Q: What are all the difference between iOS3, iOS4 and iOS5?
A:  Refer:  Apple iOS Versions and diffrences

Xcode and Others

Q Explain the options and the bars available in XCode 4.0 ?

 

*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.
From your code, access your app’s resource files using an NSBundle object:
1.    Use the mainBundle method of NSBundle to obtain your app’s main bundle object.
2.    Use the methods of the bundle object to obtain the location of the desired resource file.
3.    Open (or access) the file and use it.
The pathForResource:ofType: method is one of several NSBundle methods that you can use to retrieve the location of resource files in your bundle. The following example shows how to locate an image file called sun.png and create an image object. The first line gets the location of the file in the bundle. The second line creates the UIImage object using the data in the file at that location.

Objective C and Foundation

* 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: Why do we need to use @Synthesize?
A:  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: What is dynamic?
Ans:
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: Is a delegate retained?
Ans:  No, the delegate is never retained! Ever!

*Q: What are all the difference between categories and subclasses? Why should we go to subclasses?
Ans:  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’s subclasses.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: Whats fast enumeration?
Ans:  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?
Ans:
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: If I call performSelector:withObject:afterDelay: – is the object retained?
Ans: 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  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.

 

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

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

Q : 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>
@end
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.

http://stackoverflow.com/questions/990360/differences-between-java-interfaces-and-objective-c-protocols

 

 

Q  When to use NSMutableArray and when to use NSArray?
A : 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.
If anyone wants to adds something he/she is welcomed to do that.

Q What are KVO and KVC?
Ans :  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.

Q:  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 that property.

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

 

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

* Q: Can you explain what happens when you call autorelease on an object?
Ans:  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: What is categories in iOS?
A:  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 polymorphism?
And : 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.

* Q: Whats the NSCoder class used for?
Ans: 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?
Ans:  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 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.
Memory Management

 

*Q Is there any concept of Garbage Collector in Objective C ?
Ans: There is no Garbage collector in Objective C , Either you manage it manually by using reference counting algorithm ( retain and release messages ) Or  You can use ARC ( Compiler level feature ) that will insert these retain , release messages for you .

* Q: What happens when the following code executes?
Ball *ball = [[[[Ball alloc] init] autorelease] autorelease];
Ans: 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: What is Automatic Reference Counting (ARC)
Ans : 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: Can you just explain about memory management in iOS?
Ans: Refer: iOS Memory Management

*Q: What is the difference between retain & assign?
Ans:
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:When will be the autorelease object released?
Ans: Once the pool receives drain message.

* Q: Explain retain counts.
Ans: 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.

* Q: Implement the following methods: retain, release, autorelease.
Ans:
-(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;
}

 

UIKit

*Q: What is Controller Object?
Ans: 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, a controller) 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.

View Controller Object

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

 

*Q: Outline the class hierarchy for a UIButton until NSObject.
Ans: UIButton inherits from UIControl, UIControl inherits from UIView, UIView inherits from UIResponder, UIResponder inherits from the root class NSObject.

 

*Q: Whats the difference between frame and bounds?
Ans: 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: How would you create your own custom view?
Ans:  By Subclassing the UIView class.

*Q: What is Delegation in iOS?
Ans:

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?
Ans: 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 NSFileManager, NSWorkspace, NSApplication, 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: 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?
Ans:   YES. ,  The pool that is created in main function is capable of handling all the autorelease objects created on the main thread. Every thread must have  its own autorelease pool , so if you create secondary thread then you should also create a separate pool for there so that the objects autoreleased on the secondary thread will have their autorelease pool in place that takes care of the releasing of those autorelased obejcts.

*Q: What is notification in iOS?
Ans:   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 supplemental information.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.Regular notifications—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?
Ans:   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 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.

*Q: What is posing in iOS?
Ans: 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 difference between synchronous and asynchronous in web request?
Ans: Synchronous web request works on the main thread of the application while asynchronous wen request works on the secondary thread. As synchronous web request works  on the main thread , it blocks the user””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””s  UI interaction . Synchronous request on the other hand does not block UI ( as it runs on the secondary thread ) but at the same time can not update UI as well . Only main thread should update the UI objects. So asynchronous web request normally gives a call back to the main thread to update the UI.

*Q:What is atomic and nonatomic? Which one is safer? Which one is default?
Ans:
You can use this attribute to specify that accessor methods are not atomic. (There is no keyword to denote atomic.)
nonatomic
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 strong, copy, 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
AVAILABLE_MAC_OS_X_VERSION_10_1_AND_LATER_BUT_DEPRECATED_IN_MAC_OS_X_VERSION_10_4;
@property CGFloat y __attribute__((…));

*Q: What is run loop in iOS ?
Ans:
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?
Ans: 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?
And : 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.

*Q: What is push notification?How it works?
Ans:  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?
Ans : 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.

Graphics and Animation

*Q: Is the delegate for a CAAnimation retained?
Ans: Yes it is!! This is one of the rare exceptions to memory management rules.

Deployment

*Q: Explain the steps involved in submitting the App to App-Store.
Ans: Ref: https://developer.apple.com/appstore/resources/approval/guidelines.html

*Q: What are the App states. Explain them?
Ans:
•    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: What is code signing?
Ans:
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
Refere: App Doc for more info.

 

*Q: What is Wildcard App IDs?
Ans: 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.

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

Others

*Q What is iPhone?
Ans:
Ans: IPhone is a combination of internet and multimedia enabled smart phone developed by Apple Inc.
* iPhone functions as a camera phone, including text messaging, and visual voice mail
* iPhone is a portable media player that resembles a video iPod
* It has user interface that is built around the multi-touch screen including virtual keyboard.
* App Store , which launched in the mid 2008 has over 1,00,000 applications with functionalities including games, references, GPS navigation, advertising, television shows, films, reference, celebrities.

Q: What are the features of iphone 3gs?

Ans : Video: Videos can be edited, shared. High quality VGA video can be shot in portrait or landscape.
3 Megapixel Camera: Still photos with greater quality can be taken
Voice control: It recognizes the names in contacts and recognizes the music on iPod.
Compass: iPhone 3GS has built-in digital compass, used to point the way.
Internet Tethering: Internet surfing can be done from anywhere. A 3G connection can be shared on Iphon3 with Mac notebook or laptop..

Q: What is iphone OS?

Ans: iPhone OS runs on iPhone and iPod touch devices.
Hardware devices are managed by iPhone OS and provides the technologies needed for implementing native applications on the phone.
The OS ships with several system applications such as Mail, Safari, Phone, which provide standard services to the user.

Q: What is iphone sdk?

Ans: iPhone SDK is available with tools and interfaces needed for developing, installing and running custom native applications.
Native applications are built using the iPhone OS’s system frameworks and Objective-C language and run directly on iPhone OS.
Native applications are installed physically on a device and can run in presence or absence of network connection.

Q: iPhone architecture?

Ans : It is similar to MacOS X architecture
It acts as an intermediary between the iPhone and iPod hardware an the appearing applications on the screen
The user created applications never interact directly with the appropriate drivers, which protects the user applications from changes to the hardware.

Q: What is iphone reference library?

Ans: iPhone reference library is a set of reference documents for iPhone OS .
It can be downloaded by subscribing to the iPhone OS Library doc set.
Select Help>Documentation from Xcode, and click the subscribe button next to the iPhone OS Library doc set, which appears in the left column.

Q: What are sensors in iphone?

Ans : The proximity sensor immediately turns off the display when the iPhone is lifted to ear. With this sensor the power is saved and accidental dialing is prevented.
The display is automatically brightens the iPhone by the ambient light sensor when the sunlight or bright rooms and dims in darker places.

Q: What are the location services?

Ans : Applications such as Maps, camera and compass are allowed to use the information from cellular, Wi-Fi and Global Positioning System networks for determining the approximate locations.The location is displayed on the screen, using a blue marker.

Q: Describe the functionality of accelerometer of an iphone

Ans : iPhone responds to motion using a built-in accelerometer.The accelerometer detects the movement and changes the display accordingly, at the time of rotating iPhone from portrait to landscape.

Q: Explain about the applications that can be used with iphone

Ans : Technology, Entertainment and Design(TED): Allows to watch and listen to world’s most fascinating people have to say, all on the iPhone.
Market Watch: Breaking news about the investments can be seen. To do so, open the Stocks app and rotate.Trends: Latest runway shows, videos from Vogue’s fashion library, reviews, exclusive party pictures, fashion news updates can be seen on Style.com.

Q: Explain the use of Internet Control Message Protocol (ICMP).

Ans : Internet Control Message Protocol is one of the important protocols in the Internet Protocol suite. It is mainly used in operating system of networked computers, for the purpose of sending error messages, for example, a requested service is unavailable or the host could not be reached. It is not directed by the network applications. ICMPs are utilized by routers, hosts for communicating the updates or error information to other routers.

Q: What is the use of IGMP protocol?

Ans : Internet Group Management Protocol: – It allows internet hosts to participate in multicasting. The IGMP messages are used to learn which hosts is part of which multicast groups. The mechanism also allow a host to inform its local router, that it wants to receive messages.

Q: What are the differences between a domain and a workgroup?

Ans: In a domain, one or more computer can be a server to manage the network. On the other hand in a workgroup all computers are peers having no control on each other. In a domain, user doesn’t need an account to logon on a specific computer if an account is available on the domain. In a work group user needs to have an account for every computer.
In a domain, Computers can be on different local networks. In a work group all computers needs to be a part of the same local network.

Q: What is iPhone?
Ans : IPhone is a combination of internet and multimedia enabled smart phone developed by Apple Inc. IPhone functions as a camera phone, including text messaging, and visual voice mail. IPhone is a portable media player that resembles a video iPod. It has user interface that is built around the multi-touch screen including virtual keyboard.

Q What is an iPhone app?
Ans: An iPhone app is a program that runs on our iPhone/iPod Touch. It enables us to accomplish a certain task. They could be utility apps, games, enterprise apps, entertainment apps, apps to access our bank account etc.
Introduction to Iphone application Development?
In 2007, Apple entered the cellular phone business wz        “-with the introduction of the iPhone, a multi-touch display cell phone, which also includes the features of iPod.

 

Q: Multitasking support is available from which version?

Ans: iOS 4.0

 

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

256bytes.

Q: What are the features of iPhone 3gs?
•    Video: Videos can be edited, shared. High quality VGA video can be  shot in portrait or landscape.
•    3 Mega pixel Camera: Still photos with greater quality can be taken
•    Voice control: It recognizes the names in contacts and recognizes the music on iPod.
•    Compass: iPhone 3GS has built-in digital compass, used to point the way.
•    Internet Tethering: Internet surfing can be done from anywhere. A 3G connection can be shared on Iphon3 with Mac notebook or laptop.

Q: Why iPhone apps are popular?
Give our business a whole new way of transacting business for millions of users.
IPhones are the market leaders in the smart phone segment. The iPhone has become a great device to surf the internet, play games, interact with social networks and transact business.

Q: Where can you test Apple iPhone apps if you don’t have the device?

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

Q: Does iOS support multitasking? 
Ans: 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.

Q: Which JSON framework is supported by iOS?
Ans: 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.

Q: What is iPhone OS?
Ans: iPhone OS runs on iPhone and iPod touch devices.
Hardware devices are managed by iPhone OS and provides the technologies needed for implementing native applications on the phone.
The OS ships with several system applications such as Mail, Safari, Phone, which provide standard services to the user.

Q:  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 copy will not be affected.

Q: What are the requirements for developing iPhone Apps?
Ans: Mac OS 10.5/10.6
iPhone SDK (Software Development Kit 3.0/4.0).
IPhone SDK consists of:
•     IDE to develop iPhone Apps is XCode(This tool is inbuilt in iPhone SDK)
•     Interface Builder This is used to design GUI of Apps(Inbuilt feature of iPhone SDK)
•     Instruments  This is used to check any memory leaks in our apps (Inbuilt in SDK)
•     Simulator This is used to test our apps before deploying into real device.

Q: What are the popular apps of iPhone?
Ans:

•    Face book-Social networking
•    Doodle Buddy-drawing
•    Pandora Radio-radio on our iPhone
•    Yelp-restaurant reviews

Q: What is iPhone reference library?
Ans: iPhone reference library is a set of reference documents for iPhone OS. It can be downloaded by subscribing to the iPhone OS Library doc set. Select Help>Documentation from X code, and click the subscribe button next to the iPhone OS Library doc set, which appears in the left column.

Q: What is iPhone sdk?
Ans :iPhone SDK is available with tools and interfaces needed for developing, installing and running custom native applications. Native applications are built using the iPhone OS’s system frameworks and Objective-C language and run directly on iPhone OS. Native applications are installed physically on a device and can run in presence or absence of network connection.

Q: What is iPhone architecture?
Ans: It is similar to Mac OS X architecture
It acts as an intermediary between the iPhone and iPod hardware and the appearing applications on the screen
The user created applications never interact directly with the appropriate drivers, which protects the user applications from changes to the hardware.

Q: What are the location services?
Ans: Applications such as Maps, camera and compass are allowed to use the information from cellular, Wi-Fi and Global Positioning System networks for determining the approximate locations.
The location is displayed on the screen, using a blue marker.

Q: Describe the functionality of accelerometer of an iPhone ?
Ans: iPhone responds to motion using a built-in accelerometer.
The accelerometer detects the movement and changes the display accordingly, at the time of rotating iPhone from portrait to landscape.
Name the application thread from where UIKit classes should be used?
 
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.

Q: Which API is used to write test scripts that help in exercising the application””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””s user interface elements?

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

Q: Explain about the applications that can be used with iPhone ?
Ans:
Technology, Entertainment and Design (TED): Allows to watch and listen to world’s most fascinating people have to say, all on the iPhone.

Q: What are the tools required to develop iOS applications? 
Ans :
iOS development requires Intel-based Macintosh computer and iOS SDK.

Q: Name the framework that is used to construct application’s user interface for iOS. 
Ans :
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.

Q: What is iPhone reference library?
Ans:
iPhone reference library is a set of reference documents for iPhone OS.
It can be downloaded by subscribing to the iPhone OS Library doc set.
Select Help>Documentation from X code, and click the subscribe button next to the iPhone OS Library doc set, which appears in the left column.

Q:What are sensors in iPhone?
Ans: The proximity sensor immediately turns off the display when the iPhone is lifted to ear. With this sensor the power is saved and accidental dialling is prevented.
The display is automatically brightens the iPhone by the ambient light sensor when the sunlight or bright rooms and dims in darker places.

Q How can an operating system improve battery life while running an app?
Ans: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.

Q: Why an app on iOS device behaves differently when running in foreground than in background?

Ans: 
An application behaves differently when running in foreground than in background because of the limitation of resources on iOS devices.

Q: Which framework delivers event to custom object when app is in foreground?

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

Q: When an app is said to be in not running state?

Ans:
An app is said to be in ””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””not running”””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””” state when:
•     it is not launched.
•     it gets terminated by the system during running.

Q: Assume that your app is running in the foreground but is currently not receiving events. In which sate it would be in?

Ans: 
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.
Q: How can you respond to state transitions on your app?

Ans: 
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.
Q: List down app””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””s state transitions when it gets launched.

Ans: 
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.
Q: Who calls the main function of you app during the app launch cycle?

Ans: 
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 hand over control to the UIKit framework, which takes care of initializing the app before it is run.

Q: Give example scenarios when an application goes into InActive state?

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

Q: When an app is said to be in active state?

Ans: 
An app is said to be in active state when it is running in foreground and is receiving events.
Q: Name the app sate which it reaches briefly on its way to being suspended.

Ans: 
An app enters background state briefly on its way to being suspended.

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

Q: Whats fast enumeration?
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 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 frame and bounds?
Ans:
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 what is id?
Ans:
– id is a generic reference type. The variable declared using id data-type can hold any object. Most of the methods that returns an object has ‘id’ as return type. Ex – init.

Q Explain memory management?
Ans:
Most of the object oriented languages have the Garbage Collector .  All the objects are allocated on the heap memory. The Garbage Collector is a thread that runs periodically to check all the objects, which are no more being referenced from the program. Garbage collector then de-allocates all these unreferenced objects on the Heap. In this environment programmer does not need to worry about de-allocating the objects explicitly.
In Objective – C we don’t have garbage collector. ( Note: Its available from iOS 5.0 only). So in this environment we have to explicitly take care of allocation and deallocation of all the objects in our program.  And to manage this Objective C uses ‘reference counting’ algorithm as the memory management algorithm.
Reference Counting: In this algorithm every object keeps track of it owners ( I,e reference variables from the program ) . No of owners is represented by the property retainCount declared in NSObject. If this retainCount goes to ‘0’ the object gets deallocated automatically.  We never call dealloc method on any object explicitly.

Q what is dealloc?
Ans :
– dealloc method is called on an object to actually deallocate the memory for that object. ( We should never call dealloc directly )
– In reference counting environment when retainCount of an object reaches to ‘0’, the dealloc method is called on that object automatically to delete the memory space of the object .
– If the object is having some reference type variable holding other objects, then we should call release method on every variable in dealloc
– If you override then [super dealloc] should be the last line in this method.

 

Q What is Autorelease pool?

Ans
–  Autorelease pool is like a container that holds the autoreleased objects .
– This pool is drained with every run-loop of the Application
– When the pool gets drained, autorelease pool sends a release message to all the objects it was holding.

Q What is Foundation Framework? Can you explain some classes from that?
– Foundation is one of the important frameworks in COCOA Touch.
– It contains the classes like  NSArray , NSString , NSObject etc .

Q What is iPhone Architecture?

Ans. It is similar to MacOS X architecture. It acts as an intermediary between the iPhone and iPod hardware an the appearing applications on the screen. The user created applications never interact directly with the appropriate drivers, which protects the user applications from changes to the hardware.

Q What is MVC ? MVC Architecture of iPhone App.

Ans. Here are the reasons why we should use the MVC (Model View Controller)design pattern.

– They are resuable : When the problems occurs, there is no need to invent a new solution, we just have to follow the pattern and adopt it as necessary.

–  They are expressive: By using the MVC design pattern our application becomes more expressive.

1).  Model: The model object knows about all the data that need to be displayed. It is model who is aware about all the operations that can be applied to transform that object. It only represents the data of an application. The model represents enterprise data and the business rules that govern access to and updates of this data. Model is not aware about the presentation data and how that data will be displayed to the browser.

2). View: The view represents the presentation of the application. The view object refers to the model. It uses the query methods of the model to obtain the contents and renders it. The view is not dependent on the application logic. It remains same if there is any modification in the business logic. In other words, we can say that it is the responsibility of the of the view””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””s to maintain the consistency in its presentation when the model changes.

3). Controller:  Whenever the user sends a request for something then it always go through the controller. The controller is responsible for intercepting the requests from view and passes it to the model for the appropriate action. After the action has been taken on the data, the controller is responsible for directing the appropriate view to the user. In  GUIs, the views and the controllers often work very closely together.

Q What are the ways to store data localy on device ?

Ans. We store data localy in device through:

  • 1.    Plist.
  • 2.    NSUserDefaults.
  • 3.    SQLite.
  • 4.    CoreData.

 

Q Difference between COCOA,COCOA touch and objective C ?

Ans. Objective C is a dynamic programming language – a bit like C++ and a bit like Java.
Cocoa is the application framework for Mac OS X. Cocoa Touch is the application framework for iPhone and iPod Touch – very similar to Cocoa. Cocoa is commonly referred to as the combination of the Foundation and AppKit frameworks, while Cocoa Touch is the combination of the Foundation and UIKit frameworks. Cocoa and Cocoa Touch sit on top of other collections of frameworks to create the API stacks. The other layers are Media, Core Services and Core OS. The main difference between Cocoa and Cocoa touch is that the UI classes and APIs aren””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””t the same as Mac OS X, so instead of NSTextField, you have UITextField. Many of the classes share the same functionality and can be ported quite easily by simply changing the class name, though most will require some more changes, but usually nothing too heavy. There are also some differences between the Foundation frameworks in Cocoa and Cocoa Touch, mostcommonly missing classes, eg, Cocoa has NSHost and Cocoa Touch doesn””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””t.

 

Q What is SOAP [Simple Object Access Protocol]?
Ans.
SOAP is an XML-based messaging protocol. It defines a set of rules for structuring messages that can be used for simple one-way messaging but is particularly useful for performing RPC-style (Remote Procedure Call) request-response dialogues. It is not tied to any particular transport protocol though HTTP is popular. Nor is it tied to any particular operating system or programming language so theoretically the clients and servers in these dialogues can be running on any platform and written in any language as long as they can formulate and understand SOAP messages. As such it is an important building block for developing distributed applications that exploit functionality published as services over an intranet or the internet.
Q Can you give example for SOAP Format?

Ans.
< soap:Envelope xmlns:soap=”http://www.w3.org/2001/12/soap-envelope” soap:encodingStyle=”http://www.w3.org/2001/12/soap-encoding”> 
< soap:Header> 
… 
… 
< /soap:Header> 
< soap:Body> 
… 
… 
< soap:Fault> 
… 
… 
< /soap:Fault> 
… 
< /soap:Body> 
< /soap:Envelope>
Q Difference between GET and POST methods –

Ans.

  • Fundamental Difference is probably the Visibility – GET request is sent via the URL string (appended to the URI with a question-mark as separator), which is visible whereas POST request is encapsulated in the body of the HTTP request and can””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””t be seen.
  •  Length – Since, GET request goes via URL, so it has a limitation for its length. It can””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””t be more than 255 characters long (though this is browser dependent, but usually the max is 255 characters only). Whereas no such maximum length limitation holds for the POST request for the obvious reason that it becomes a part of the body of the HTTP request and there is no size limitation for the body of an HTTP request/response.
  •  Performance – GET request is comparatively faster as it””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””s relatively simpler to create a GET request and the time spent in the encapsulation of the POST request in the HTTP body is saved in this case. In addition, the maximum length restriction facilitates better optimization of GET implementation.
  • Type of Data – GET request is sent via URL string and as we all know that URL can be text-only, so GET can carry only text data whereas POST has no such restriction and it can carry both text as well as binary data.
  • Caching/Bookmarking – again for the obvious reason that a GET request is nothing but an URL hence it can be cached as well as Bookmarked. No such luxuries with a POST request.
  •  FORM Default – GET is the default method of the HTML FORM element. To submit a FORM using POST method, we need to specify the method attribute and give it the value “POST”.
  • Data Set – GET requests are restricted to use ASCII characters only whereas POST requests can use the ””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””enctype”””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””” attribute with a value “multipart/form-data” to use
   Also refer this link:- http://www.diffen.com/difference/Get_vs_Post

 

Q What is NSThread?

Ans. An NSThread object controls a thread of execution. Use NSThread when you want to have an Objective-C message run in its own thread of execution or if you need to terminate or delay the current thread. A thread is an executable unit. A task is made up of one or more threads. Each thread has its own execution stack and is capable of independent input/output. All threads share the virtual memory address space and communication rights of their task. When a thread is started, it is detached from its initiating thread. The new thread runs independently. That is, the initiating thread does not know the new thread””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””s state.

Q: Swap the two variable values without taking third variable?
Ans:-
int x=10;
int y=5;
x=x+y;
NSLog(@”x==> %d”,x);
y=x-y;
NSLog(@”Y Value==> %d”,y);
x=x-y;
NSLog(@”x Value==> %d”,x);

Text Field with input from Picker : BCTextField

Hi Everyone , This post explains how to user BCTextField  ( source code is hosted on Github https://github.com/BharatJagtap/BCTextField ) in an iPhone App . This text field is capable of taking input from a picker in place of a regular keyboard. Lets  quickly see the final output .

1) Picker Text Field

First screen shot above displays a text field. When you tap on the text field , it brings the picker from the bottom instead of regular keyboard. User can then select a particular value from the picker. There is also done button which hides the picker. The code to create this text field looks like below.

    textField2 = [[BCTextField alloc]init];
    textField2.borderStyle = UITextBorderStyleRoundedRect;
    textField2.frame = CGRectMake(10, 100, 300, 30);
    textField2.bcDelegate = self;
    textField2.type = BCTextFieldTypePicker;
    textField2.items = [NSArray    arrayWithObjects:@”Red”,@”Green”,@”Blue”,@”Black”,@”White”, nil];
    textField2.placeholder = @”Color”;

[self.view addSubview: textField2];

You just need to set the type to BCTextFieldTypePicker to type property and an array of strings to the items property of the text field and rest will be taken care by the text field it self.

2) Date Picker Text Field
Second screen shot displays the date picker instead of a regular keyboard. Creating it is again very much simple . Lets check out how to do that.

    textField3 = [[BCTextField alloc]init];
    textField3.borderStyle = UITextBorderStyleRoundedRect;
    textField3.frame = CGRectMake(10, 150, 300, 30);
   // set the type of the text field as like in the above example but this time to
      BCTextFieldTypeDatePicker
     textField3.type = BCTextFieldTypeDatePicker;
  // setting the datePickerMode
    textField3.datePickerMode = UIDatePickerModeDateAndTime;
    // You can even set the dateformatter . the text displayed in the text field after selecting the date would be formatted using this date formatter object. Its an optional though . If you dont set it The default date would be displayed in the default format as in the screen shot
   NSDateFormatter * dtFormatter = [[NSDateFormatter alloc]init];
    [dtFormatter setDateFormat:@”dd-MM-yyyy”];
    textField3.dateFormatter = dtFormatter;
    [self.view addSubview:textField3];
Later on when you submit the form or anywhere in your controller , if you want to access the date then you can access the date property of the textField
   NSDate * date = textField3.date ;
BCTextField on iPad

BCTextField created on iPad will show popover for the picker and datePicker instead of bringing it from the bottom in place of the regular keyboard. This behavior makes more sense on ipad . It would look like like below on ipad.
Input Type Date Picker on 
The sample demo code and the source code is available on githubhttps://github.com/BharatJagtap/BCTextField . Download and drag the below files to your project . Thats it , you are good to use them.
1) BCTextField.h
2) BCTextField.m
3) left.png
4) right.png

Input Type Picker on Ipad
The sample demo code and the source code is available on githubhttps://github.com/BharatJagtap/BCTextField . Download and drag the below files to your project . Thats it , you are good to use them.
1) BCTextField.h
2) BCTextField.m
3) left.png
4) right.png

Simple Animation Demo in Android, Using Multithreading

Hi All,
This is a sample application demonstrating how to Animate using AysncTask.
Ball class will draw itself by moving in a particular direction.
Ball class will hold it””””s radius, x y co-ordinates , color and the direction in which it should move. The move method of class Ball will manage the x,y co-ordinates depending on it””””s direction. The following is the class Ball .
———————————————————————————————————————–
package in.bitcode.animationdemo;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
public class Ball {
    int x, y, r;
    Paint paint;
    String direction;
    public Ball( int x, int y, int r, int color, String direction ) {
        this.x = x; this.y = y; this.r = r;
        paint = new Paint();
        paint.setColor(color);
        this.direction = direction;
    }
    public void move(Canvas canvas ) {
        if( direction.equals(“up”) ) {
            y–;
        }
        if( direction.equals(“right”) ) {
            x++;
        }
        if( direction.equals(“down”) ) {
            y++;
        }
        if( direction.equals(“left”) ) {
            x–;
        }
        draw(canvas);
    }
    public void draw( Canvas canvas ) {
        canvas.drawCircle(x, y, r, paint);
    }
}

———————————————————————————————————————–

MyImageView class
MyImageview class is extending the class ImageView.
It will contain four Ball objects, initialized to move up, right, down and left. Their initial position will be center of the screen.  It””””s onDraw method is overridden which will call the move method on each ball by passing it the Canvas object.
We will be having a Thread which will invalidate this MyImageView after some interval so that the onDraw of MyImageView is called which will in turn call the move method on each ball contained inside it.
Following is the class MyImageView:

———————————————————————————————————————–
package in.bitcode.animationdemo;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.widget.ImageView;

public class MyImageView extends ImageView {

Ball bup, bright, bdown, bleft;

public MyImageView(Context context, int width, int height ) {
super(context);
bup = new Ball( width/2, height/2, 20, Color.RED,”up”);
bright = new Ball( width/2, height/2, 20, Color.GREEN,”right”);
bdown = new Ball( width/2, height/2, 20, Color.BLUE,”down”);
bleft= new Ball( width/2, height/2, 20, Color.YELLOW,”left”);
}

@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
bup.move( canvas );
bright.move( canvas );
bdown.move( canvas );
bleft.move( canvas );
}

}
——————————————————

The Home class:

Home class extends the Activity class. Home activity class will create an object of class MyImageView and set it as content view. It will have and inner class MyThread which will be extending the class AsyncTask. MyThread will invalidate the MyImageView after certain interval.

Following is the Home class, it is containing an inner class Mythread:

————————————————
package in.bitcode.animationdemo;import android.app.Activity;
import android.os.AsyncTask;
import android.os.Bundle;public class Home extends Activity {

MyImageView view;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

view = new MyImageView(this, getWindowManager().getDefaultDisplay().getWidth(), getWindowManager().getDefaultDisplay().getHeight() );
setContentView(view);

new MyBallThread().execute(null);

}

class MyBallThread extends AsyncTask<Object, Object, Object> {

@Override
protected Object doInBackground(Object… params) {
for( int i = 0; i < 200; i++ ) {
publishProgress(null);
try {
Thread.sleep(100);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return null;
}

@Override
protected void onProgressUpdate(Object… values) {
// TODO Auto-generated method stub
super.onProgressUpdate(values);
view.invalidate();
}

}

}

————————————————

–  Android @ BitCode Technologies Pvt. Ltd. – No. 1 Mobile  Training Company in Pune

“Pioneers in Mobile Computing Training”

Find more about us at http://www.bitcode.in

iPhone Interview questions with Answers (iPhone @ BitCode )

Hello All , find below some iPhone interview questions . I hope this will help you to face the technical interview . I will be modifying this post with some more questions and answers in a couple of days , so keep checking this post for more .

1. What is @interface?
- It’s a keyword used to declare the Class.
2. What is @implementation?
- It’s a keyword used to define the Class.
3. Garbage collector in iPhone?
- iOS 5.0 has got the ARC ( Automated reference counting ).  Objective C does not have a garbage collector rather it uses the reference counting algorithm to manage the memory. This was the developers task until Apple launched iOS 5.0. Again if you are targeting iOS 4.0 or earlier , ARC is no more a choice for you .
4. What is delegate?
- Delegate is an object that handles the events happening on an object. To do that delegate has to follow a protocol specifying the task it is going to handle .
5. What is @synthesize?
- We use @synthesize to generate getters and setters automatically from compiler.  We declare properties and then generate getter and setter method by using @synthesize.
6. What are the features of iOS 5.0 ?
- https://developer.apple.com/technologies/ios5/
7. What is nonatomic ?
- nonatomic and atomic are related to multithreading environment .
 – If a property has an attribute as “nonatomic” that means multiple threads can modify that property concurrently.
- If the attribute is “atomic”, the threads would be given access atomically.
-  So “Atomic” is thread safe while “nonatomic” is thread unsafe.
- Atomic drastically hampers the performance so until and unless not needed you should never go for atomic attribute. ‘nonatomic ’ will do in most of the cases.
8. What are the delegate methods of MKMapView ?
- Check the MKMapViewDelegate in the Documentation. If you don’t have Xcode with you then search on Google.
9. What are the important delegate methods of NSXML parser?
-DidStartElement
-FoundCharecters
-DidEndElement
-FoundError
10. What is @dynamic and any place where it is used ?
- It tells compiler that getter and setter are not implemented by the class but by some other class .
- May be super class or child class .
Example – Core Data
-       The Managed object classes have properties defined by using @dynamic.
11. What is @property?
- It is a keyword used to declare a property.
12. What is data source?
- The datasource is an object that implements the required datasource protocol that is needed to create a complex control.
Ex UITableView is a view that needs a datasource object to which will help building the table. Often it’s the controller that is displaying the table view. The protocol that dataSource object ( mostly controller it self) has to implement is “UITableViewDataSource” .
13. What is model view controller?
- MVC is a Design pattern .
Model stands for the database  object which will manage all the database transaction .
- View stands for the UI i.e. the UI visible to the user. User will be interacting with the view.
- Controller is an object who handles the view events and also render the database changes to the UI. In short , it bridges the interaction between Modal and View.
14. what is @ protocol?
- @protocol is a keyword used to define a protocol. A protocol is a set of method declarations defining specific purpose. It only lists out the methods prototype , the actual implantation would be provided by the class that implements /  follows the protocol.
15. what is id?
- id is a generic reference type. The variable declared using id data-type can hold any object. Most of the methods that returns an object has ‘id’ as return type. Ex – init.
16. Explain memory management?
- Most of the object oriented languages have the Garbage Collector .  All the objects are allocated on the heap memory. The Garbage Collector is a thread that runs periodically to check all the objects, which are no more being referenced from the program. Garbage collector then de-allocates all these unreferenced objects on the Heap. In this environment programmer does not need to worry about de-allocating the objects explicitly.
In Objective – C we don’t have garbage collector. ( Note: Its available from iOS 5.0 only). So in this environment we have to explicitly take care of allocation and deallocation of all the objects in our program.  And to manage this Objective C uses ‘reference counting’ algorithm as the memory management algorithm.
Reference Counting: In this algorithm every object keeps track of it owners ( I,e reference variables from the program ) . No of owners is represented by the property retainCount declared in NSObject. If this retainCount goes to ‘0’ the object gets deallocated automatically.  We never call dealloc method on any object explicitly.
17. what is retain and release?
- retain and release are two method defined in NSObject . – -
- These methods are related to Memory Mangement .
- retain method when called increases the retainCount by 1.
- release method when called decreases the retainCount by 1
18. what is dealloc?
- dealloc method is called on an object to actually deallocate the memory for that object. ( We should never call dealloc directly )
- In reference counting environment when retainCount of an object reaches to ‘0’, the dealloc method is called on that object automatically to delete the memory space of the object .
- If the object is having some reference type variable holding other objects, then we should call release method on every variable in dealloc.
- If you override then [super dealloc] should be the last line in this method.
19. What is Autorelease pool?
-  Autorelease pool is like a container that holds the autoreleased objects .
- This pool is drained with every run-loop of the Application
- When the pool gets drained, autorelease pool sends a release message to all the objects it was holding.
20. What is Foundation Framework? Can you explain some classes from that?
- Foundation is one of the important frameworks in COCOA Touch.
- It contains the classes like  NSArray , NSString , NSObject etc .
21. What is the difference between NSArray and NSMutableArray?
* NSArray
-        is a static array
-       Once created you can not modify the array
-       Ex you can not add or remove the object in NSArray.
* NSMutableArray
-       is a dynamic array
-       You can add or remove the object dynamically.
22. Write a delegate method of the table view?
 – (void)tableView:( UITableView*)tableView didSelectRowAtIndexPath:(NSIndexPath*)indexPath
23. What are the delegate methods of NSURLConection?
- didReceiveResponse:
- didReceiveData:
- didFinishLoadingData:
- didFailWithError:
24. What is cocoa ?
- COCOA is a collection of frameworks used to write Applications for MAC OS X.
25. Singleton classes
- A singleton class is such a class from which no more that one instance can be created. So there will always be single instance created throughout the program.
Ex UIApplication.

BitCode Blog

Hi All,

We are happy to introduce our blog at http://bitcode.in/blog.
We hope that this blog will help you find most of the technical stuff you need everyday. Also we promise to put lots of innovative stuff here on our blog.

Thank You.
Admin BitCode