July 2005
Beginner
719 pages
19h 54m
English
After you have created the Discus project, replace the contents of the Discus.m file with the following code:
#import <Foundation/Foundation.h>
int main (int argc, const char * argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
// Store data in an array of dictionaries
NSArray *discs =
[NSArray arrayWithObjects:
[NSDictionary dictionaryWithObjectsAndKeys:
@"CD", @"Type",
[NSNumber numberWithInt:3], @"LengthInMinutes",
@"Lounge Room", @"Location",
@"BB Bonkas", @"Artist",
nil],
[NSDictionary dictionaryWithObjectsAndKeys:
@"CD", @"Type",
[NSNumber numberWithInt:4], @"LengthInMinutes",
@"Attic", @"Location",
@"CC Charmers", @"Artist",
nil],
[NSDictionary dictionaryWithObjectsAndKeys:
@"DVD", @"Type",
[NSNumber numberWithInt:121], @"LengthInMinutes",
@"Attic", @"Location", @"TJ Slickflick", @"Lead Actor", @"LJ Slickflick", @"Director", nil], nil]; // Extract a few entries, and print them in the console NSLog(@"The third entry in the library is a %@", [[discs objectAtIndex:2] objectForKey:@"Type"]); NSLog(@"The director is %@", [[discs objectAtIndex:2] objectForKey:@"Director"]); // Write the array to file NSString *path = [NSHomeDirectory() stringByAppendingPathComponent:@"Desktop/discus.plist"]; [discs writeToFile:path atomically:YES]; // Read the array back from the file, and write it to the console NSArray *newDiscs = [[[NSArray alloc] initWithContentsOfFile:path] autorelease]; NSLog(@"The database contents are:\n%@", ...
Read now
Unlock full access