Amazon.com Widgets Program 15.12
Welcome, Guest. Please login or register.
Did you miss your activation email?
June 20, 2013, 05:12:54 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 15
| | | |-+  Program 15.12
Pages: [1]   Go Down
Print
Author Topic: Program 15.12  (Read 1302 times)
TotalLuck
Full Member
***
Posts: 107



WWW Email




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

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

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

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 = @"jewls337@axlc.com";
NSString *bName = @"Tony Iannino";
NSString *bEmail = @"tony.iannino@techfitness.com";
NSString *cName = @"Stephen Kochan";
NSString *cEmail = @"steve@kochan-wood.com";
NSString *dName = @"Jamie Baker";
NSString *dEmail = @"jbaker@kochan-wood.com";


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];
else
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;

}
[/pre]
Logged

Apps available on  iTunes store:
"ADACode"  iPhone and iPad versions, "ADAGuidelines" iPhone & iPad versions,  "Rehabilitation Act of 1973" for iPhone
"APokerTimer" now for iPhone http://bit.ly/h1fAJp
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.