Greg’s Online CS 193P Resources

April 19, 2009

Matching the Declaration and Use of a Method

Filed under: cs 193p,iPhone — gregorykaiser @ 6:01 am
Tags:

A question on the Auditor list got me to make a code snip that shows what must match for a method (in this case “description”).

// PolygonShape.h – Declare It!

@interface PolygonShape : NSObject {
int numberOfSides;
int minimumNumberOfSides;
int maximumNumberOfSides;
}

@property (readonly) NSString * description;

———————-
// PolygonShape.m – Define it!

#import “PolygonShape.h”


– (NSString *)description; {
NSLog(@”Hello I am a %d-sided polygone (aka a %@) with angles of %f degrees (%f radians)”, self.numberOfSides,
[self name], [self angleInDegrees], [self angleInRadians]);
return (NSString *)[self name];
}
———————-
// WhatATool.m – Use It!

#import “PolygonShape.h”

PolygonShape *p2 = [[PolygonShape alloc] initWithNumberOfSides:6 minimumNumberOfSides:5 maximumNumberOfSides:9]; // alloc
[marray addObject:p2];
[[marray objectAtIndex:1] description];

Advertisements

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Blog at WordPress.com.

%d bloggers like this: