Mobianhero
Mobianhero

Reputation: 279

simple method returns in objective c

I am currently new to objective c and have came across a problem while making a game I have a custom made object called battleEngine which is an instance variable in my helloWorld scene in cocos2d. That object has an object as an instance variable called plyController which is a PlayerController object. I want battleEngine to have a getter method that returns the plyController object and this code doesn't work:

-(PlayerController*)getPlayerController
{
 return plyController;
}

Upvotes: 0

Views: 77

Answers (1)

Abizern
Abizern

Reputation: 150745

Is there any reason you haven't just declared your player controller object as a property? You could just use the synthesised getter in that case to get the player controller.

Have a look at the documentation on properties.

Also, and I'm afraid I have to say this or they will take my Cocoa-programmer badge away from me, getPlayerController is not a good method name. Methods with get in them are conventionally used to return values in the parameters passed in by reference. The Cocoa Coding Guidelines tells us this, and much more.

Upvotes: 6

Related Questions