1. Welcome to the new MacRumors forums. See our announcement and read our FAQ

Classes

Discussion in 'iPhone/iPad Programming' started by Nnavick, Oct 19, 2010.

  1. macrumors regular

    #1
    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
     
  2. Moderator

    dejo

    Staff Member

    #2
    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.
     
  3. macrumors regular

    #3
    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]

    ?
     
  4. Moderator

    dejo

    Staff Member

    #4
    No, that just declares an object (and, technically, it just declares a pointer to that object). You haven't instantiated it yet.
     
  5. macrumors regular

    #5
    So how do I initialize the class?
     
  6. Moderator

    robbieduncan

    Staff Member

    #6
    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.
     

Share This Page