Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Nnavick

macrumors regular
Original poster
Oct 13, 2010
100
0
Hi,
I wrote a class that calculate point ,

the .M file of the class:

Code:
#import "GameBrain.h"


@implementation GameBrain


-(int)CalculatePoint:(int)ArrowPoint,int NewPoint {
	if(ArrowPoint>NewPoint) {
	 NewArrowPoint=ArrowPoint-NewPoint;
	 NewArrowPoint*=-1;
	}
	else 
		NewArrowPoint=NewPoint-ArrowPoint;
	
	return NewArrowPoint;
}


@end

the .H file of the class:

Code:
#import <Foundation/Foundation.h>


@interface GameBrain : NSObject {

	int NewArrowPoint;
}



-(int)CalculatePoint:(int) ArrowPoint,int NewPoint;
@end

How do I call the class and the method "CalculatePoint" from the main program ?

Thanx
 
Code:
-(int)CalculatePoint:(int) ArrowPoint,int NewPoint;
First, are you sure you want to be using unconventional syntax like this?

How do I call the class and the method "CalculatePoint" from the main program ?
Second, you don't "call a class". A class is simply a definition that you can use to create an object of its type, a process known as instantiation.
 
First, are you sure you want to be using unconventional syntax like this?


Second, you don't "call a class". A class is simply a definition that you can use to create an object of its type, a process known as instantiation.

By creating an object you mean ,
Code:
GameBrain * game;
what next? when I write [game and then escape i can't see the methods of the class]

?
 
So how do I initialize the class?

I think, given this question, that you need to stop writing code and learn the basics of the language. This really is about as basic as it gets.

Edit to add: you should read, and understand, all of this document. If you don't understand something don't skip over it. Stop, think about it, re-read until you are sure you understand what is going on.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.