2 Replies Latest reply: Feb 21, 2010 2:26 PM by musicwind95
musicwind95 Level 4 Level 4 (1,280 points)
I was working on an exercise, and I'm trying to invoke the description method, but it didn't work properly. I can't figure out the issue.

Here's my custom description method:

-(NSString *) description
NSString *description = [[NSString alloc] init];
[description stringByAppendingFormat: @"Hello, I am a %d sided figure (a %@) with angle measures of %.2f degrees (%.2f radians).", self.numberOfSides, [self name], [self angleInDegrees], [self angleInRadians]];
[description autorelease];
return description;

and here's the function I'm trying to get to work:

void PrintPolygonInfo () // Function declaration for Section 6
NSMutableArray *polygons = [[NSMutableArray alloc] init];

// Add polygons to array

PolygonShape *shape1 = [[PolygonShape alloc] init];
shape1.minimumNumberOfSides = 3;
shape1.maximumNumberOfSides = 7;
shape1.numberOfSides = 4;
[polygons addObject: shape1];
NSLog (@"Shape 1 added. It has a message: %@", shape1);

PolygonShape *shape2 = [[PolygonShape alloc] initWithNumberOfSides: 6 minimumNumberOfSides: 5 maximumNumberOfSides: 9];
[polygons addObject: shape2];
NSLog (@"Shape 2 added. It has a message:");

PolygonShape *shape3 = [[PolygonShape alloc] initWithNumberOfSides: 12 minimumNumberOfSides: 9 maximumNumberOfSides: 12];
[polygons addObject: shape3];
NSLog (@"Shape 3 added. It has a message:");

// Enumerate through array and change properties

for (PolygonShape *shape in polygons)
[shape setNumberOfSides: 10];

// Verify deallocation

[shape1 release];
[shape2 release];
[shape3 release];
[polygons release];

The NSLogs after each object was added to the array is not printing from the description method. What's the issue?

iMac 8,1 stock—OS .VI.II • iPod Touch 1,1—OS 3.1.2, D-link DIR-625 router • iLife 09 • iWork 09 • XCode 3.2.1 (64-bit)