Official Forum for Programming in Objective-C (the iPhone Programming Language) - Stephen Kochan
December 10, 2018, 03:22:30 PM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
   Home   Help Search Login Register Chat  
Pages: [1]   Go Down
Author Topic: Program 15.12  (Read 2370 times)
Full Member
Posts: 107

WWW Email
« on: February 15, 2009, 04:04:31 PM »

RemoveCard Method interface
Code: (Objective-C)
-(void) removeCard: (AddressCard *) theCard;

RemoveCard Method Implementation
Code: (Objective-C)
-(void) removeCard: (AddressCard *) theCard
[book removeObjectIdenticalTo: theCard];

test Program
Code: (Objective-C)
#import <Foundation/NSObject.h>
#import <Foundation/NSString.h>
#import "AddressBook.h"

int main(int argc, char *argv[])
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSString *aName = @"Julia Kochan";
NSString *aEmail = @"";
NSString *bName = @"Tony Iannino";
NSString *bEmail = @"";
NSString *cName = @"Stephen Kochan";
NSString *cEmail = @"";
NSString *dName = @"Jamie Baker";
NSString *dEmail = @"";

AddressCard *card1 = [[ AddressCard alloc] init];
AddressCard *card2 = [[ AddressCard alloc] init];
AddressCard *card3 = [[ AddressCard alloc] init];
AddressCard *card4 = [[ AddressCard alloc] init];

// set up Four addressCards

[card1 setName: aName andEmail: aEmail];
[card2 setName: bName andEmail: bEmail];
[card3 setName: cName andEmail: cEmail];
[card4 setName: dName andEmail: dEmail];

AddressBook *myBook = [ AddressBook alloc];
AddressCard *myCard;

// Now initialize the Adress Book
myBook = [ myBook initWithName:@"L=inda's Address Book"];

//add some cards to the address book
[myBook addCard: card1];
[myBook addCard: card2];
[myBook addCard: card3];
[myBook addCard: card4];

// look up a person by name

NSLog (@"Lookup: Stephen Kochan");
myCard = [myBook lookup: @"Stephen Kochan"];

if (myCard != nil)
[myCard print];
NSLog(@"Not Found!");

// now remove the entry form the book

[myBook removeCard: myCard];
[myBook list]; // verify its gone

[card1 release];
[card2 release];
[card3 release];
[card4 release];

[pool drain];

return 0;


Apps available on  iTunes store:
"ADACode"  iPhone and iPad versions, "ADAGuidelines" iPhone & iPad versions,  "Rehabilitation Act of 1973" for iPhone
"APokerTimer" now for iPhone
Pages: [1]   Go Up
Jump to:  

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 ゥ 2009 All rights reserved.