Wednesday, 16 March 2011

Basic Collections

Sample List and Map:


(header file)

interface RootViewController : UITableViewController {
    NSMutableArray* drinks;
    NSDictionary* drinkMap;
}
@property(nonatomic, retain) NSMutableArray* drinks;
@property(nonatomic, retain) NSDictionary* drinkMap;



.... and initing the array:



// Load directly
drinks = [[ NSMutableArray alloc] initWithObjects: @"Mojito", @"Long Island Iced Tea", @"Firecracker", nil];

// Load from a resource (prefered - its all about the plists).
NSString *path = [[NSBundle mainBundle] pathForResource: @"DrinkDirections" ofType: @"plist"];

drinks = [[ NSMutableArray alloc] initWithContentsOfFile:path];

// Note well: If you are initing a big plist dictionary then load it in as an Array and once you have an element that bit is a Dictionary.

No comments:

Post a Comment