Amazon.com Widgets Program 15.11
Welcome, Guest. Please login or register.
Did you miss your activation email?
April 24, 2014, 04:48:38 PM
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.11
Pages: [1] Go Down
Print
Author Topic: Program 15.11 (Read 1532 times)
TotalLuck
Full Member
***
Posts: 107



WWW Email




on: February 15, 2009, 03:56:28 PM

Lookup method added to AddressBook.h
Code: (Objective-C)
-(AddressCard *) lookup: (NSString *) theName;
[/pre]

Lookup method added to AddressBook.m
Code: (Objective-C)
-(AddressCard *) lookup: (NSString *) theName
{
for (AddressCard *nextCard in book)
if ( [[nextCard name] caseInsensitiveCompare: theName] == NSOrderedSame)
return nextCard;

return nil;
}
[/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!");

// try another lookup


NSLog (@"Lookup: Haibo Zhang");
myCard = [myBook lookup: @"Haibo Zhang"];

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


[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.