Tuesday, February 7, 2012

A dictionary is a collection of data consisting of key-object pairs. Just as you would look up the definition of a word in a dictionary, you obtain the value (object) from an Objective- C dictionary by its key.
#import <Foundation/NSObject.h>
#import <Foundation/NSString.h>
#import <Foundation/NSDictionary.h>
#import <Foundation/NSAutoreleasePool.h>
int main (int argc, char *argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
NSMutableDictionary *glossary = [NSMutableDictionary dictionary];
// Store three entries in the glossary
[glossary setObject: @”A class defined so other classes can inherit from it” forKey: @”abstract class” ];
[glossary setObject: @”To implement all the methods defined in a protocol” forKey: @”adopt”];
[glossary setObject: @”Storing an object for later use” forKey: @”archiving”];
// Retrieve and display them
NSLog (@”abstract class: %@”, [glossary objectForKey: @”abstract class”]); NSLog (@”%@”, [glossary objectForKey: @”adopt”]); NSLog (@”%@”, [glossary objectForKey: @”archiving”]);


}
[pool drain]; return 0;
Program Output
abstract class: A class defined so other classes can inherit from it adopt:
To implement all the methods defined in a protocol archiving: Storing an object for later use

No comments:

Post a Comment