## What am I doing wrong in this peace of code

410 Views 4 Replies Latest reply: Oct 14, 2012 9:36 AM by RL6001
Calculating status...
Currently Being Moderated
Oct 14, 2012 3:14 AM

Hi All,

I'm currently reading "Learn Objective-c on the mac" (I have finished "Learn C on the mac").

The code beneith is from the makers of the book. When I run this code in Xcode there are two problems.

Just run and you will see (I don't understand the meaning of the problem, so it's hard to explain it here).

My version of Xcode is 4.4.1

#import <Foundation/Foundation.h>

// --------------------------------------------------

// constants for the different kinds of shapes and their colors

typedef enum {

kRedColor,

kGreenColor,

kBlueColor

} ShapeColor;

// --------------------------------------------------

// Shape bounding rectangle

typedef struct {

int x, y, width, height;

} ShapeRect;

// --------------------------------------------------

// convert from the ShapeColor enum value to a human-readable name

NSString *colorName (ShapeColor color)

{

switch (color) {

case kRedColor:

return @"red";

break;

case kGreenColor:

return @"green";

break;

case kBlueColor:

return @"blue";

break;

}

return @"no clue";

} // colorName

// --------------------------------------------------

@interface Circle : NSObject

{

ShapeColor  fillColor;

ShapeRect   bounds;

}

- (void) setFillColor: (ShapeColor) fillColor;

- (void) setBounds: (ShapeRect) bounds;

- (void) draw;

@end // Circle

@implementation Circle

- (void) setFillColor: (ShapeColor) c

{

fillColor = c;

} // setFillColor

- (void) setBounds: (ShapeRect) b

{

bounds = b;

} // setBounds

- (void) draw

{

NSLog (@"drawing a circle at (%d %d %d %d) in %@",

bounds.x, bounds.y,

bounds.width, bounds.height,

colorName(fillColor));

} // draw

@end // Circle

// --------------------------------------------------

@interface Rectangle : NSObject

{

ShapeColor    fillColor;

ShapeRect    bounds;

}

- (void) setFillColor: (ShapeColor) fillColor;

- (void) setBounds: (ShapeRect) bounds;

- (void) draw;

@end // Rectangle

@implementation Rectangle

- (void) setFillColor: (ShapeColor) c

{

fillColor = c;

} // setFillColor

- (void) setBounds: (ShapeRect) b

{

bounds = b;

} // setBounds

- (void) draw

{

NSLog (@"drawing a rectangle at (%d %d %d %d) in %@",

bounds.x, bounds.y,

bounds.width, bounds.height,

colorName(fillColor));

} // draw

@end // Rectangle

// --------------------------------------------------

@interface OblateSphereoid : NSObject

{

ShapeColor    fillColor;

ShapeRect    bounds;

}

- (void) setFillColor: (ShapeColor) fillColor;

- (void) setBounds: (ShapeRect) bounds;

- (void) draw;

@end // OblateSphereoid

@implementation OblateSphereoid

- (void) setFillColor: (ShapeColor) c

{

fillColor = c;

} // setFillColor

- (void) setBounds: (ShapeRect) b

{

bounds = b;

} // setBounds

- (void) draw

{

NSLog (@"drawing an egg at (%d %d %d %d) in %@",

bounds.x, bounds.y,

bounds.width, bounds.height,

colorName(fillColor));

} // draw

@end // OblateSphereoid

// --------------------------------------------------

// Draw the shapes

void drawShapes (id shapes[], int count)

{

int i;

for (i = 0; i < count; i++) {

id shape = shapes[i];

[shape draw];

}

} // drawShapes

// --------------------------------------------------

// The main function.  Make the shapes and draw them

int main (int argc, const char * argv[])

{

id shapes[3];

ShapeRect rect0 = { 0, 0, 10, 30 };

shapes[0] = [Circle new];

[shapes[0] setBounds: rect0];

[shapes[0] setFillColor: kRedColor];

ShapeRect rect1 = { 30, 40, 50, 60 };

shapes[1] = [Rectangle new];

[shapes[1] setBounds: rect1];

[shapes[1] setFillColor: kGreenColor];

ShapeRect rect2 = { 15, 19, 37, 29 };

shapes[2] = [OblateSphereoid new];

[shapes[2] setBounds: rect2];

[shapes[2] setFillColor: kBlueColor];

drawShapes (shapes, 3);

return (0);

} // main

#### More Like This

• Retrieving data ...

#### Legend

• This solved my question - 10 points
• This helped me - 5 points
This site contains user submitted content, comments and opinions and is for informational purposes only. Apple disclaims any and all liability for the acts, omissions and conduct of any third parties in connection with or related to your use of the site. All postings and use of the content on this site are subject to the Apple Support Communities Terms of Use.