Frame, Bounds and center in IOS?


Frame A view's frame (CGRect) is the position of its rectangle in the superview's coordinate system. By default it starts at the top left.
Bounds A view's bounds (CGRect) expresses a view rectangle in its own coordinate system.
Center A center is a CGPoint expressed in terms of the superview's coordinate system and it determines the position of the exact center point of the view.

How to make a NSURL Request and parse the XML response?


   
#import "ViewController.h"
#import "XMLReader.h"


      
     //first you need to create a URL using String.
      NSURL *url = [NSURL URLWithString:@"feed://feeds.feedburner.com/blogspot/MKGLf?format=xml"];
           
      //Once you create a URL,you are ready make a request.
       NSURLRequest *request = [NSURLRequest requestWithURL:url];
        
       //After making request the apparent thing is expecting the response that may be expected response or an Error. so create those objects and initialize them with NULL.
        NSURLResponse *response = NULL;
NSError *requestError = NULL;
      //Once you have response with you, capture your responseData using NSData.
       NSData *responseData = [NSURLConnection sendSynchronousRequest:request        returningResponse:&response error:&requestError];

        //Convert the response data into response String.
NSString *responseString  = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];

        //Now you can start parsing the data using XML parser. You need XML parser in-order to     use the below class method "dictionaryForXMLString"
NSError *parserError = NULL;

      
NSDictionary *xmlDict = [XMLReader dictionaryForXMLString:responseString error:NULL]; 

        //Once You have xmlDict handy, you can pass this to the any ViewController(like tableview) to populate the data.

       

What is the difference between the Release and Autorelease?

Release and Autorelease are the terms related to the Memory Management. whenever you own a object its your responsibility to release it . if you don't release it properly, Objective -C cannot reclaim it for the use of other objects and there will be a memory leak.

                                                        Different ways to own a object are alloc, new , retain and copy Whenever you use this things try to release it so Objective C will take care blowing that object. If you are not sure about releasing that object,  please make sure you do autorelease.

                                                         Whenever you do autorelease of an object the object is not released right way,  it will be added to the Autoreleasepool in the main function. The Autoreleasepool in the main function will maintain a stack of objects to be released and they are released one by  one when "drain"method is called eg: [pool drain]. Drain method is called repeatedly at the end of every event loop.

what is the event loop?

For instance when you click on the button  in the application, button goes and performs what needs to done and comes back to the normal state of the app this is considered as one event loop.

What is Retain Count or Reference Counting?

Retain Count is the term which is related to the Memory Management . whenever you create a object, Objective C doesn't really care about the object you have created , the area of memory is claimed for this object and retain count is increased by one.

                     YourClass *yourObj  = [ YourClass alloc] init];
                      ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
                      [obj someMethod];
                        [yourObj release];

whenever you release that object the retain count does  go down by one ,whenever the retain count reaches zero, Objective C blows that object and it will be ready to reclaim that memory for another Object.
                 
                   YourClass *yourObj  = [ YourClass alloc] init];
                   [someOtherObj someMethod];
                   [yourObj release];
                 
whenever you pass  "yourObj" to  someMethod of someOtherObj, then a retain message is passed to that object and retain count increased to two. someOtherObj will take care of reducing the retain count to one when it is done and the regular release that you made will reduce it to zero.

Here "yourObj" is the pointer variable that stores the memory address of the object (or) simply it is reference to the object. Even after the object is blown from the memory address of the memory still present in "yourObj" variable called dangling pointer but it refers to the nil object.

if you want to learn about what happens when you pass a message to nil Object, you can follow this link


What is Memory Management in Objective C?

Objective C wants you to manage memory for every Object you create, you don't have to do this with ints, chars, floats and bools but just objects. it doesn't matters whether those object are coming from your classes (or) frameworks. whenever you own a object by doing alloc, new, copy and retain you should make sure that its your responsibility to release that Object.

                      In many languages like Java, C#, ruby, python etc you just make the variables you need and language itself takes care of cleaning up the stuff. This is usually done by the part of the language named Garbage Collector. Even Objective C has kind of garbage collector but wasn't actually part of the language, they just added couple of years back. Garbage collector can't be used on iPhone , iPad and mac prior to Leopard so if you have to write code for those you have to do manually.

                      Garbage collection is never default in Object C, you have to choose and change the settings in the project you are working and often write code to opt into garbage collector. To even use Garbage collection you have to understand the manual memory management

For more information on how we can manage memory in different ways read Difference between Release and Autorelease

What is the difference between NSArray and NSMutableArray?

Regular NSArray is Immutable , i,e  whenever you create an NSArray object and initialize some values to that and later sometime in the project if u have to add some value or object to that instance of an array it won't let u do that.

NSArray *myArray = [NSArray arrayWithObjects: @"1", @"two", @"3", nil];

Here unlike the C-style Arrays you don't explicitly declare the size of an array, it will automatically does it until it hits nil.
The problem here is, sometime later if u want to add or remove object , you will not be able to do with the regular arrays. NSMutableArray which is the subclass of NSArray does this for you.

NSMutableArray *myArray = [NSArray arrayWithObjects: @"1", @"two", @"3", nil];

sometime later  if you want to add a string or object to this array, there are methods in NSMutableArray which lets you to do this.

[myArray addObject: @"four"];
[myArray removeObjectAtIndex:2];

What is the advantage of Arrays in objective C over C-style Arrays

We all know that an Array is the ability of a variable to hold the multiple values at the same time. Objective C supports C-Style way of doing the things and also has its own way which is much better than C.

First Lets talk about the C-style way of playing with  single values  and arrays.

C-style single value declaration and assigning
    
       int singleValue;    
       singleValue = 10; ( the value is stored in the variable named singleValue)

In this case Objective C  claims the memory space that can hold the SingValue and the max it can spare is 4 bytes since we are using int has a datatype.

C-style Arrays

      int multipleValues[3] ;

So here Objective C  claims the memory space that can hold 3 values  and each of 4 bytes maximum. Now you can start assigning values, you have to start from index 0 since in C and Objective C arrays are  Zero based.

         multipleValues[0] = 23;
         multipleValues[1] = 13;
         multipleValues[2] = 34;

or    
    
         multipleValues[3] = {23, 13, 34}

So what if you need to add an element to that array  in the future?

          multipleValues[3] = {23, 13, 34, 77}
Objective C will warn you that you have an excess element in array initializer. This limitation of fixed width is overcome'd in Objective C.

So what if you need to to access the element that you did't claim it before.

          multipleValue[55] = 88;

When you run this, it still works fine so there is no bound checking is done. This works better in Objective C way of doing the thing with NSArray.

So what if you need to mix the types in arrays like ints, floats and bool . C-style of doing the things doesn't let u do that but Objective classes which are added on top of C like NSArray will allow you to do all these things.

Does Objective C supports Multiple Inheritance?

The answer is NO. Objective C has the single Inheritance, all its behavior is inherited from the single super or parent class called NSObject.