Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make a forward declaration for private method?

I'm arranging my methods into groups using #pragma mark in implementation. But sometimes, the method implementation code appears below the code that calls this method, and I'm getting "Instance method not found" warnings. It happens when I'm using private methods. How to fix that?

like image 423
Centurion Avatar asked Nov 11 '11 13:11

Centurion


People also ask

What is forward declaration in PL SQL?

This declaration makes that program available to be called by other programs even before the program definition. Remember that both procedures and functions have a header and a body. A forward declaration consists simply of the program header followed by a semicolon (;). This construction is called the module header.

How do you forward a function declaration?

To write a forward declaration for a function, we use a function declaration statement (also called a function prototype). The function declaration consists of the function header (the function's return type, name, and parameter types), terminated with a semicolon. The function body is not included in the declaration.

What is forwarding declaration?

A forward declaration tells the compiler about the existence of an entity before actually defining the entity. Forward declarations can also be used with other entity in C++, such as functions, variables and user-defined types.

Where do you put forward declaration?

Generally you would include forward declarations in a header file and then include that header file in the same way that iostream is included.


2 Answers

Simplest method is to use a anonymous category. Add something like this to the top of your .m file, before your @implementation:

@interface MyClass()
- (void)myPrivateMethod;
@end
like image 196
DarkDust Avatar answered Sep 20 '22 03:09

DarkDust


In your Class.m implementation file, you can add an interface section at the beginning and declare private functions in there:


@interface YourClassName (private)

-(void)aPrivateMethod:(NSString*)aParameter;
...

@end

@implementation YourClassName
...
@end

like image 24
TheEye Avatar answered Sep 20 '22 03:09

TheEye