Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > Mac OS X Development Forums > Objective-C, Python, Ruby Development

Reply
 
LinkBack Thread Tools Display Modes
Old 10-22-2009, 12:43 PM   #1 (permalink)
Registered Member
 
Join Date: Oct 2009
Posts: 39
Arcadiu is on a distinguished road
Default Accessor Methods

I am stuck in this book I am reading and its about accessor methods and the reason I am here is because I don't understand the code because the author doesn't explain it very well.

All I am asking is just some notes beside each line telling me what is happening in all this code

Code:
@interface Car : NSObject 
{ 
    Engine *engine; 
    Tire *tires[4]; 
} 
- (Engine *) engine; 
- (void) setEngine: (Engine *) newEngine; 
- (Tire *) tireAtIndex: (int) index; 
- (void) setTire: (Tire *) tire 
         atIndex: (int) index; 
- (void) print; 
@end // Car
Code:
@implementation Engine
- (Engine *) engine 
{ 
    return (engine); 
} // engine 
- (void) setEngine: (Engine *) newEngine 
{ 
    engine = newEngine; 
} // setEngine
Code:
Engine *engine = [Engine new]; 
[car setEngine: engine]; 
NSLog (@"the car's engine is %@", [car engine]);
Code:
- (void) setTire: (Tire *) tire 
         atIndex: (int) index; 
- (Tire *) tireAtIndex: (int) index;
Code:
@implementation Tire
- (void) setTire: (Tire *) tire 
          atIndex: (int) index 
{ 
    if (index < 0 || index > 3) { 
        NSLog (@"bad index (%d) in setTire:atIndex:", 
               index); 
        exit (1); 
    } 
    tires[index] = tire; 
} // setTire:atIndex: 
- (Tire *) tireAtIndex: (int) index
{
    if (index < 0 || index > 3) { 
        NSLog (@"bad index (%d) in "tireAtIndex:", 
               index); 
        exit (1); 
    } 
    return (tires[index]); 
} // tireAtIndex:
Code:
Tire *tire = [Tire new]; 
        
    [car setTire: tire 
         atIndex: 2]; 
    NSLog (@"tire number two is %@", 
           [car tireAtIndex: 2]);
I know this is a lot of code but I am really stuck.

If this is not needed in iPhone Dev PLEASE tell me Thanks

Arc
Arcadiu is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 465
13 members and 452 guests
Domele, Duncan C, Feldspar, MacBook MH, Objective Zero, patapple, peterwilli, pipposanta, PixelInteractive, Punkjumper, SLIC, taylor202, Today's Posts
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,694
Threads: 94,137
Posts: 402,950
Top Poster: BrianSlick (7,990)
Welcome to our newest member, peterwilli
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 01:04 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0