Monday, June 18, 2012

passing multiple arguments...



Into a method:


- - - In ExampleClass.h - - -
#import <Foundation/Foundation.h>
@interface ExampleClass : NSObject { int age, weight; }
@property int age, weight; // declared to be modifiable
-(void) print;
-(void) datableAge: (int) a: (int) i;
@end
- - - in ExampleClass.m - - -
#import "ExampleClass.h"
@implementation ExampleClass
@synthesize age, weight;
-(void) print{ NSLog(@"I am @i years old and weigh %i pounds", age, weight); }
-(void) datableAge: (int) a: (int) i
{ NSLog(@"You can date chicks %i years old", (a/2+7)-(i/100000)); }

@end
- - - in MainProgram.m - - -
#import <Foundation/Foundation.h>
#import "ExampleClass.h"
int main (int argc, const char * argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
ExampleClass *ClassInstanceVariable = [[ExampleClass alloc] init];
ClassInstanceVariable.age = 12;
ClassInstanceVariable.weight = 140;
[ ClassInstanceVariable datableAge: 75:300000];
[ ClassInstanceVariable print ];
[ ClassInstanceVariable release]; // related to memory management.
[pool drain];
return 0;
}

- BE


No comments:

Post a Comment