Wednesday, March 20, 2013

iPhone Interview Questions and Answers


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.

Friday, April 6, 2012

Route-Me Offline Mapping from Database

Please go through these below link
http://www.gisnotes.com/wordpress/2010/08/iphone-dev-note-21-route-me-offline-mapping-from-database/

http://support.cloudmade.com/answers/offline-maps
http://support.cloudmade.com/forums/iphone-sdk/posts/104/show

Thursday, March 15, 2012

Xcode Problems Redux: You don’t have permission to save the file “iOS DeviceSupport” in the folder “Xcode”


Xcode Problems Redux: You don’t have permission to save the file “iOS DeviceSupport” in the folder “Xcode”.


So we have another problem with Xcode: You don’t have permission to save the file “iOS DeviceSupport” in the folder “Xcode”. To view or change permissions, select the item in the Finder and choose File > Get Info
Some pretty shitty info. But I’ve played around a bit and found a fix.
1. Open up the terminal app
2. Execute the command:
sudo chmod 777 /Users//Library/Developer/Xcode
3. Disconnect your device and reconnect it
4. In the organiser, under devices press Add to Portal
5. Xcode should now add your device for development.
Hope this helps anyone out there :)

EXC_BAD_ACCESS on iPhone

how to debug EXC_BAD_ACCESS on iPhone

http://www.codza.com/how-to-debug-exc_bad_access-on-iphone


If you set the NSZombieEnabled environment variable, the Objective C runtime will leave a dummy object behind for every deallocated object. When the zombie object is called, execution stops and you can see the message that was sent to the object and the call stack that tells you where the message came from (it doesn’t tell you where you over released the object, but knowing where the object is called from should get you pretty close to the problem.)
To set this variable, go to the info panel of the executable in xcode, and create a newenvironment variable in the arguments tab by clicking the plus sign in the lower left corner of the window. Name the variable NSZombieEnabled, type YES for the value and make sure that the checkbox is selected.

set NSZombieEnabled variable


Tuesday, February 14, 2012

Renaming Project in XCode 4


Renaming Project in XCode 4 :  
Some are having trouble figuring out how to rename projects in Xcode 4. As it happens, Apple’s made things quite easy. It renames the project and the product names of any targets sharing the project’s nameand any strings it finds in your nib/xib files. In theory, that is.
Here’s how:
  1. Open the project in Xcode 4.
  2. Click the project itself in the Project Navigator.
  3. Open the Utility pane (the right-most button in the View button panel in the right side of the toolbar).
  4. Select the File Inspector utility pane if it’s not already.
  5. Under the Identity group, set the Project Name field to whatever you like and press return.
  6. You’ll be asked which items to rename (including any targets or strings in nib/xib files sharing the same name as the project).
  7. Cherry pick which ones you want to rename (probably all of them) by unchecking those you don’t, then click Rename.
  8. You may be asked to take a snapshot of the project. My advice? Do it. Xcode 4 still has bugs and crashed on me the first time I tried this, resulting in a screwed up project. Click Enable to enable snapshots if asked.
  9. Assuming there are no errors, all checked items will have a green checkmark next to them and the rename sheet’s button will turn to Ok. Click it and you’re done.

Friday, December 30, 2011

iPad Launch Image Orientations


iPad Launch Image Orientations
To deal with various orientation options, a new naming convention has been created for iPad launch images. The screen size of the iPad is 768×1024, notice in the dimensions that follow the height takes into account a 20 pixel status bar.
Filename Dimensions
Default-Portrait.png * 768w x 1004h
Default-PortraitUpsideDown.png 768w x 1004h
Default-Landscape.png ** 1024w x 748h
Default-LandscapeLeft.png 1024w x 748h
Default-LandscapeRight.png 1024w x 748h
Default.png Not recommended
  • If you have not specified a Default-PortraitUpsideDown.png file, this file will take precedence.
** If you have not specified a Default-LandscapeLet.png or Default-LandscapeRight.png image file, this file will take precedence.

Tuesday, August 23, 2011

Divide value in three string


double distRemain = distInMeter;
originalDistRemain = distInMeter;
if(distRemain >0 && distRemain <10){
lblDistance.text = @"0";
lblDistance1.text = @"0";
int lastdigit = distRemain/1;
lblDistance2.text = [NSString stringWithFormat:@"%d",lastdigit];
 
}
else if(distRemain >=10 && distRemain < 100){
lblDistance.text = @"0";
int lasttwo = distRemain/10;
lblDistance1.text = [NSString stringWithFormat:@"%d",lasttwo];
distRemain = distRemain -(lasttwo *10);
int lastdigit = distRemain/1;
lblDistance2.text = [NSString stringWithFormat:@"%d",lastdigit];
}
else if(distRemain >=100 && distRemain < 1000){
int firstDigit = distRemain/100;
lblDistance.text = [NSString stringWithFormat:@"%d",firstDigit];
distRemain = distRemain - (firstDigit *100);
int lasttwo = distRemain/10;
lblDistance1.text = [NSString stringWithFormat:@"%d",lasttwo];
distRemain = distRemain -(lasttwo *10);
int lastdigit = distRemain/1;
lblDistance2.text = [NSString stringWithFormat:@"%d",lastdigit];
}