Search Posts in my Blog

Wednesday 12 December 2012

NSAttributedString in iOS 6


infoString=@"This is an example of Attributed String";



NSMutableAttributedString *attString=[[NSMutableAttributedString allocinitWithString:infoString];
NSInteger _stringLength=[infoString length];

UIColor *_black=[UIColor blackColor];
UIFont *font=[UIFont fontWithName:@"Helvetica-Bold" size:30.0f];
[attString addAttribute:NSFontAttributeName value:font range:NSMakeRange(0, _stringLength)];
[attString addAttribute:NSForegroundColorAttributeName value:_black range:NSMakeRange(0, _stringLength)];



               









UIColor *_red=[UIColor redColor];
UIFont *font=[UIFont fontWithName:@"Helvetica-Bold" size:72.0f];
[attString addAttribute:NSFontAttributeName value:font range:NSMakeRange(0, _stringLength)];
[attString addAttribute:NSStrokeColorAttributeName value:_red range:NSMakeRange(0, _stringLength)];
[attString addAttribute:NSStrokeWidthAttributeName value:[NSNumber numberWithFloat:3.0range:NSMakeRange(0, _stringLength)];















UIColor *_red=[UIColor redColor];
UIFont *font=[UIFont fontWithName:@"Helvetica-Bold" size:72.0f];
[attString addAttribute:NSFontAttributeName value:font range:NSMakeRange(0, _stringLength)];
[attString addAttribute:NSStrokeColorAttributeName value:_red range:NSMakeRange(0, _stringLength)];
[attString addAttribute:NSStrokeWidthAttributeName value:[NSNumber numberWithFloat:-3.0range:NSMakeRange(0, _stringLength)];

















UIColor *_red=[UIColor redColor];
UIColor *_green=[UIColor greenColor];
UIFont *font=[UIFont fontWithName:@"Helvetica-Bold" size:72.0f];
[attString addAttribute:NSFontAttributeName value:font range:NSMakeRange(0, _stringLength)];
[attString addAttribute:NSForegroundColorAttributeName value:_green range:NSMakeRange(0, _stringLength)];
[attString addAttribute:NSStrokeColorAttributeName value:_red range:NSMakeRange(0, _stringLength)];
[attString addAttribute:NSStrokeWidthAttributeName value:[NSNumber numberWithFloat:-3.0]range:NSMakeRange(0, _stringLength)];



















UIColor *_green=[UIColor greenColor];
UIFont *font=[UIFont fontWithName:@"Helvetica-Bold" size:72.0f];

NSShadow *shadowDic=[[NSShadow allocinit];
[shadowDic setShadowBlurRadius:5.0];
[shadowDic setShadowColor:[UIColor grayColor]];
[shadowDic setShadowOffset:CGSizeMake(03)];
              
[attString addAttribute:NSFontAttributeName value:font range:NSMakeRange(0, _stringLength)];
[attString addAttribute:NSForegroundColorAttributeName value:_green range:NSMakeRange(0, _stringLength)];
[attString addAttribute:NSShadowAttributeName value:shadowDic range:NSMakeRange(0, _stringLength)];
                



















UIColor *_red=[UIColor redColor];
UIFont *font=[UIFont fontWithName:@"Helvetica-Bold" size:72.0f];
[attString addAttribute:NSFontAttributeName value:font range:NSMakeRange(0, _stringLength)];
  [attString addAttribute:NSForegroundColorAttributeName value:_red range:NSMakeRange(0, _stringLength)];              
  [attString addAttribute:NSKernAttributeName value:[NSNumber numberWithInt:5range:NSMak








UIColor *_red=[UIColor redColor];
UIFont *font=[UIFont fontWithName:@"Helvetica-Bold" size:30.0f];
[attString addAttribute:NSFontAttributeName value:font range:NSMakeRange(0, _stringLength)];
[attString addAttribute:NSForegroundColorAttributeName value:_red range:NSMakeRange(0, _stringLength)];
[attString addAttribute:NSUnderlineStyleAttributeName value:[NSNumber numberWithInt:2range:NSMakeRange(0, _stringLength)];








UIColor *_blue=[UIColor blueColor];
UIColor *_blueL=[UIColor colorWithRed:0 green:0 blue:0.5 alpha:0.7];
UIFont *font=[UIFont fontWithName:@"Helvetica-Bold" size:30.0f];
                
[attString addAttribute:NSFontAttributeName value:font range:NSMakeRange(0, _stringLength)];
[attString addAttribute:NSForegroundColorAttributeName value:_blue range:NSMakeRange(0, _stringLength)];
[attString addAttribute:NSBackgroundColorAttributeName value:_blueL range:NSMakeRange(020)];


                





iHope this helped you :)

Wednesday 3 October 2012

Create Indexed UITableView



Tackling that handy index on the right side of table views is really not that complicated. In fact, it only requires that you implement two methods. In this tutorial, I’m going to take you step-by-step on how to wire it all together.

Indexed Table 2


1 .Set up your project

In Xcode, go to File -> New Project and choose Navigation-based Application from the iPhone OS tab. Name the applicationIndexedTable. At this point, you should have a runnable app with an empty table in it.

2. Create a data source

Instead of hardcoding a bunch of values, country names and whatnot, let’s create a simple method that will generate a bunch of strings from the letters of the alphabet so that our UITableView has something to work with.
Create a new class called DataGenerator. Right-click on the Classes group in the project browser and choose New File. Let the file be an Objective-C class (subclass of NSObject) and name it DataGenerator. This class will only have one static method (for now) that will simply return an array of words from letters. As such, we’ll name it wordsFromLetters.

In DataGenerator.h, insert the following code:
@interface DataGenerator : NSObject {
}
 
+ (NSArray *) wordsFromLetters;
 
@end
Now, let’s implement this method. Open DataGenerator.m and put this code in it:
@implementation DataGenerator
 
#define WORD_LENGTH 5
 
static NSString *letters = @"abcdefghijklmnopqrstuvwxyz";
 
+ (NSArray *) wordsFromLetters {
    NSMutableArray *content = [NSMutableArray new];
 
    for (int i = 0; i < [letters length]; i++ ) {
        NSMutableDictionary *row = [[[NSMutableDictionary alloc] init] autorelease];
        char currentWord[WORD_LENGTH + 1];
        NSMutableArray *words = [[[NSMutableArray alloc] init] autorelease];
 
        for (int j = 0; j < WORD_LENGTH; j++ ) {
            if (j == 0) {
                currentWord[j] = toupper([letters characterAtIndex:i]);
            }
            else {
                currentWord[j] = [letters characterAtIndex:i];
            }
            currentWord[j+1] = '\0';
            [words addObject:[NSString stringWithCString:currentWord encoding:NSASCIIStringEncoding]];
        }
        char currentLetter[2] = { toupper([letters characterAtIndex:i]), '\0'};
        [row setValue:[NSString stringWithCString:currentLetter encoding:NSASCIIStringEncoding]
               forKey:@"headerTitle"];
        [row setValue:words forKey:@"rowValues"];
        [content addObject:row];
    }
 
    return content;
}
 
@end
I’m not going to spend a whole of time explaining what’s going on here because this tutorial is really about adding an index bar to your UITableView. But let’s briefly talk what’s it all about. This method loops through an array letters one-by-one. For each letter it then generates a bunch of words to fill up our content. The final structure of the NSArray we’re returning is going to look something like this:
NSArray =>
  1. NSDictionary
    • headerTitle => ‘A’
    • rowValues => {”A”, “Aa”, “Aaa”, “Aaaa”}
  2. NSDictionary
    • headerTitle => ‘B’
    • rowValues => {”B”, “Bb”, “Bbb”, “Bbbb”}
  3. etc.
You’ll see how we’re using this array later on. Also note that this list is implicitly ordered.

3. Fill in UITableView with values from DataGenerator

Next we’re going to populate the currently empty table with data we get from our data generator. Open RootViewController.h and add these two instance variables to the class:
#import "DataGenerator.h"
 
@interface RootViewController : UITableViewController {
    NSArray *content;
    NSArray *indices;
}
content will hold our array of dictionaries while indices will hold all initial letters for each word in the list. Let's fill those up. OpenRootViewController.m implementation file and override the method viewDidLoad with the following:
- (void)viewDidLoad {
    [super viewDidLoad];
    content = [DataGenerator wordsFromLetters];
    indices = [[content valueForKey:@"headerTitle"] retain];
}
You can see that we're using [DataGenerator wordsFromLetters] to simply fill in the content variable. The second line of that method returns all keys from the dictionaries in content as an array. So indices now holds all letters of the alphabet.
We next override the two methods that tell our UITableView how many sections it has and how many rows there are in each section.
// Customize the number of sections in the table view.
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return [content count];
}
 
// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return [[[content objectAtIndex:section] objectForKey:@"rowValues"] count] ;
}
The number of sections is equal to the number of letters in our list and the number of rows of each section is equal to the count of each array under its corresponding letter.
Finally, we implement cellForRowAtIndexPath so that it displays words from our list in the table. We handle headers for sections intitleForHeaderInSection. This method queries our content at a particular section and demands a headerTitle to be returned as header of that section.
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
 
    static NSString *CellIdentifier = @"Cell";
 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
                                       reuseIdentifier:CellIdentifier] autorelease];
    }
    cell.textLabel.text = [[[content objectAtIndex:indexPath.section] objectForKey:@"rowValues"]
                           objectAtIndex:indexPath.row];
 
    return cell;
}
You should be able to run your app now (CMD + R) and see something like this:
Indexed Table 01

4. Add index to the table

There is nothing new in what we've done so far. We simply filled in a UITableView with some data. We're now ready to add our index to it. For that, we'll need to implement two methods: sectionIndexTitlesForTableView and sectionForSectionIndexTitle.
Add this code to RootViewController.m:
- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView {
    return [content valueForKey:@"headerTitle"];
}
 
- (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index {
    return [indices indexOfObject:title];
}
sectionIndexTitlesForTableView: In order to properly render the index, the UITableView needs to know all index titles to display. This method returns an array of strings containing all indices. In our case, A, B, C, D, etc.
sectionForSectionIndexTitle: When you start scrolling through the index, the table needs to know how far down/up to scroll so that the letter you're touching corresponds the appropriate section in the table. This method returns an index value (integer) of the section you're currently touching in the index.
One more thing we need to do before we run our app is to add titles to each section header in UITableView.
- (NSString *)tableView:(UITableView *)aTableView titleForHeaderInSection:(NSInteger)section {
 return [[content objectAtIndex:section] objectForKey:@"headerTitle"];
 
}

5. Run your app

If everything went well, you should now be able to run your app and see the final product. You'll see the index on the right and scrolling over it will scroll the table appropriately.

indexedtable02

Conclusion

Voilà! That wasn't that hard was it? The main get-away from this tutorial are the two methods you need to implement in order for the index to show up and function properly: sectionIndexTitlesForTableView: and sectionForSectionIndexTitle:.

The complete source code for this tutorial can be found here: Indexed UITableView

Monday 27 August 2012

NSUserDefaults Tutorial



In this tutorial I will demonstrate how to use the NSUserDefaults class in order to save and update application settings. In the process, we will build a demo app called “Contact” that will store a user-supplied image and contact information.

What is the NSUserDefaults Class?

With the NSUserDefaults class, you can save settings and properties related to application or user data. For example, you could save a profile image set by the user or a default color scheme for the application. The objects will be saved in what is known as the iOS “defaults system”. The iOS defaults system is available throughout all of the code in your app, and any data saved to the defaults system will persist through application sessions. This means that even if the user closes your application or reboots their phone, the saved data will still be available the next time they open the app!
With NSUserDefaults you can save objects from the following class types:
  • NSData
  • NSString
  • NSNumber
  • NSDate
  • NSArray
  • NSDictionary
If you want to store any other type of object, such as a UIImage, you will typically need to archive it or wrap it in an instance of NSData, NSNumber, or NSString.
Now that you know a bit about what can be done with NSUserDefaults, let’s jump into learning how to use the defaults system with a simple sample app that will store contact information.

Step 1: Creating the Project

Open Xcode and select “Create a new Xcode project”. Select a View-based Application and click Next. Enter a name for your project (I’ve called mine “Contact”). Enter your Company Identifier and make sure you select iPhone for Device Family, because we are going to make an iPhone app. If you are done, click next. Choose a place to save your project and then click create.
NSUserDefaults Figure 1

Step 2: Designing the Interface

In the “Contact” folder in the “Project Navigator” click on ContactViewController.xib.
Drag three UITextFields from the library to the view and arrange them like below. Do the same with a UIImageView and two Round Rect Buttons.
Click The first TextField and type “First name” in the Placeholder text field. Now click the second TextField and type “Last name” in the Placeholder text field. At last, click the third and last TextField and type “age” in the Placeholder text field. For keyboard type, select Number Pad, because you will only need numbers to enter your age.
Change the text of the first button to “Save” and the text of the second button to “Choose Image”.
NSUserDefaults Figure 2
Now we are going the make the connections. Xcode 4 has an new easy and fast way to do so. Select the middle button of the Editor to show the “Assistant editor”.
NSUserDefaults Figure 3
Click the first name TextField and CTRL-drag to the interface. A pop-up will show, enter “firstNameTextField” for name and click “connect.”
NSUserDefaults Figure 3
Do the same with the Last name and age Text Field and the UIImageView, but call them lastNameTextField, ageTextField and contactImageView. For the buttons we need to change the connection to Action instead of Outlet. So CTRL-drag from the save button to the interface, but this time under the curly braces. Change the Connection to Action and enter “save” for name. Do the same with the Choose Image button, but this time enter “chooseImage” for name. Now the code of the ContactViewController.h should read as follows:
#import <UIKit/UIKit.h>

@interface ContactViewController : UIViewController {
    
    IBOutlet UIImageView *contactImageView;
    IBOutlet UITextField *firstNameTextField;
    IBOutlet UITextField *lastNameTextField;
    IBOutlet UITextField *ageTextField;
}

- (IBAction)save:(id)sender;
- (IBAction)chooseImage:(id)sender;

@end
Now we are done with the interface. Click Build and Run to see if it runs okay. Enter some text and close the app. If you open the app again, you will likely see that the text you entered is still there. If so, this is caused by the built-in multitasking capability of iOS. If you delete the app from the multitasking bar and open the app again, you will see that the text you entered is gone. In this tutorial we will use NSUserDefaults to save the information entered even if you “really” close the app. This will allow the data to persist through multiple sessions.

Step 3: Choosing an Image

Switch back to the standard Editor mode, so you have more space to work within. Open ContactViewController.h and add the UIImagePickerControllerDelegate and the UINavigationControllerDelegate.
<UIImagePickerControllerDelegate, UINavigationControllerDelegate>
If you are done with that, open the ContactViewController.m and scroll down to the ChooseImage action and modify the code to read as follows:
- (IBAction)chooseImage:(id)sender 
{
    UIImagePickerController *picker = [[[UIImagePickerController alloc] init] autorelease];
    picker.delegate = self;
    picker.allowsEditing = YES;
    picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
    [self presentModalViewController:picker animated:YES];
}
First, we create a UIImagePickerController, then we set the delegate to self. Next, we enable user editing, then set the source type to the photo library, and finally we show it with an animation to the user.
Under choose image action, ad the following image picker delegate methods:
#pragma mark - Image Picker Delegate

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo
{
    contactImageView.image = image;

 [picker dismissModalViewControllerAnimated:YES];
}

- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{

 [picker dismissModalViewControllerAnimated:YES];
}
In the first method, we set the contactImageView image to the selected image and then dismiss the UIImagePickerController. In the second method, we only dismiss the UIImagePickerController.

Step 4: Saving the Data

You can save text with the function: setObject:(id) forKey:(NSString *). The key needs to be a specific key for the object you save because you also need that key to get the saved data. You can save integers with the function: setInteger:(NSInteger) forKey:(NSString *). To save the image we first need to create an instance of NSData from it.
Go to the save action and modify the code to read as follows:
- (IBAction)save:(id)sender 
{
    // Hide the keyboard
    [firstNameTextField resignFirstResponder];
    [lastNameTextField resignFirstResponder];
    [ageTextField resignFirstResponder];
    
    // Create strings and integer to store the text info
    NSString *firstName = [firstNameTextField text];
    NSString *lastName  = [lastNameTextField text];
    int age = [[ageTextField text] integerValue];
    
    // Create instances of NSData
    UIImage *contactImage = contactImageView.image;
 NSData *imageData = UIImageJPEGRepresentation(contactImage, 100);

    
    // Store the data
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    
    [defaults setObject:firstName forKey:@"firstName"];
    [defaults setObject:lastName forKey:@"lastname"];
    [defaults setInteger:age forKey:@"age"];
    [defaults setObject:imageData forKey:@"image"];
    
    [defaults synchronize];
    
    NSLog(@"Data saved");
}
First we hide the keyboard. Then we create strings of the text you entered in the first and last name text field. We also create an integer of the age you entered. Than we store the image from contactImageView as an NSData object, because we can’t save a UIImage directly with NSUserDefaults. Then we store the data, we call the standardUserDefaults function to save data in it. At last we synchronize the standardUserDefaults database.

Step 5: Get the Saved Data

At last we want to get the saved data. We do this in the viewDidLoad method, because that method is called when the application opens. Scroll down to the “viewDidLoad” method, uncomment it, and modify the code as follows:
- (void)viewDidLoad
{
    // Get the stored data before the view loads
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    
    NSString *firstName = [defaults objectForKey:@"firstName"];
    NSString *lastName = [defaults objectForKey:@"lastname"];
    
    int age = [defaults integerForKey:@"age"];
    NSString *ageString = [NSString stringWithFormat:@"%i",age];
    
    NSData *imageData = [defaults dataForKey:@"image"];
 UIImage *contactImage = [UIImage imageWithData:imageData];
    
    // Update the UI elements with the saved data
    firstNameTextField.text = firstName;
    lastNameTextField.text = lastName;
    ageTextField.text = ageString;
    contactImageView.image = contactImage;
    
    [super viewDidLoad];
}
First we call the standardUserDefaults function again, so we can get the saved data. We put the first and last name in an NSString. Although the age is an integer, we create a string to store it, because we can’t directly set the text of an TextField to an integer. We put the image in an NSData object and then we create a UIImage from the NSData object. Finally, we update the UI element with the saved data.
Now that the app is finished, build and run it again. Enter your data and select an image. Close the app from the multitasking bar and then open the app again. The data should still be there this time, and if so, our demo app works!
Thanks for reading this tutorial about NSUserDefaults! If you have questions or comments on this tutorial, leave them in the comments section below!

Wednesday 25 July 2012

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.