Amazon.com Widgets 19.9
Welcome, Guest. Please login or register.
Did you miss your activation email?
April 19, 2014, 03:26:29 AM
Home Help Search chat Login Register 
News: Read this please.The Great Kangaroo Escape Looking for reviews of the 4th ed on Amazon!   Twitter:  @skochan
                     

+ Official Forum for Programming in Objective-C (the iPhone Programming Language) - Stephen Kochan
|-+ Old Stuff
| |-+ Program Examples
| | |-+ Chapter 19
| | | |-+ 19.9
Pages: [1] Go Down
Print
Author Topic: 19.9 (Read 1142 times)
mdeh
Full Member
***
Posts: 166






on: March 05, 2009, 06:30:10 PM

Code: (Objective-C)
#import <Foundation/NSObject.h>
#import <Foundation/NSAutoreleasePool.h>
#import <Foundation/NSString.h>
#import <Foundation/NSKeyedArchiver.h>
#import <Foundation/NSCoder.h>
#import <Foundation/NSData.h>
#import "AddressBook.h"
#import "Foo.h"




int main (int argc, const char * argv[]) {
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
Foo *myFoo1 = [ [ Foo alloc] init];
Foo *myFoo2;
NSMutableData *dataArea;
NSKeyedArchiver *archiver;
AddressBook *myBook;

NSString *aName = @"Julia Kochan";
NSString *aEmail = @"jewls337@axlc.com";
NSString *bName = @"Tony Iannino";
NSString *bEmail = @"Tony.Iannino@techfitness.com";
NSString *cName = @"Steven Kochan";
NSString *cEmail = @"steve@steve_kochan.com";
NSString *dName = @"Jamie Baker";
NSString *dEmail = @"jbaker@hitmail.com";
AddressCard *card1 = [[ AddressCard alloc] init];
AddressCard *card2 = [[ AddressCard alloc] init];
AddressCard *card3 = [[ AddressCard alloc] init];
AddressCard *card4 = [[ AddressCard alloc] init];

myBook = [AddressBook alloc];
// Fist set up 4 address cards
[card1 setName: aName andEmail: aEmail];
[card2 setName: bName andEmail: bEmail];
[card3 setName: cName andEmail: cEmail];
[card4 setName: dName andEmail: dEmail];

[myBook initWithName: @"Steve's Address Book"];

// Add some cards to the address book

[myBook addCard: card1];
[myBook addCard: card2];
[myBook addCard: card3];
[myBook addCard: card4];

[myBook sort];
[myBook list];

[myFoo1 setStrVal: @"This is the string"];
[myFoo1 setIntVal: 12345];
[myFoo1 setFloatVal: 98.6];

// Set up data area and connect it to an NSKeyedArchiver object

dataArea = [NSMutableData data];
archiver = [[ NSKeyedArchiver alloc] initForWritingWithMutableData: dataArea];
[archiver encodeObject:myBook forKey: @"myaddrbook"];
[archiver encodeObject:myFoo1 forKey: @"myfoo1"];
[archiver finishEncoding];

// Write the archived data area to a file

if (( [ dataArea writeToFile:@"myArchive"atomically:YES ] ) == NO)
NSLog(@"Archiving failed");

[archiver release];
[myFoo1 release];
[ card1 release];
[ card2  release];
[ card3  release];
[ card4  release];
[myBook release];
    [pool drain];
    return 0;
}
Logged
Pages: [1] Go Up
Print
Jump to:



Login with username, password and session length

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
Entire forum contents (c) 2009 classroomM.com. All rights reserved.