Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Private Methods in ObjC++

I need to rename a ObjC Class Implementation File into *.mm, because I'm using a C++ Framework (Box2D). After renaming the file and setting the Filetype to "sourcecode.cpp.objcpp" my following declaration of private methods produces some errors like:

error: expected identifier before 'private'

The declaration of methods:

@interface GameplayLayer(private)
 - (void)spawnTick:(ccTime)delta;
 - (void)pushSpawnTick;
@end

How can I use declarations of private methods in ObjC++?

like image 645
LeonS Avatar asked Jun 04 '26 04:06

LeonS


2 Answers

It is probably because private is a keyword in C++. You can either change it to something else like hidden or leave the category name empty (this is called a 'class continuation', you can read more about it by searching in this article.)

like image 182
Colin Gislason Avatar answered Jun 06 '26 06:06

Colin Gislason


this is the way I declare my private methods in Obj-C basically is just creating a category with no name in the .m hope this helps

//this is A.h

@interface A

- (void) publicMethod1;

@end



//this is A.m

@interface A ()

- (void) privateMethod1;

@end

@implementation A

- (void) publicMethod1
{
    //foo
}

- (void) privateMethod1
{
    //foo
}

@end
like image 40
Camilo Sanchez Avatar answered Jun 06 '26 06:06

Camilo Sanchez