How do I call a static bool method in main.m
This is Objective-C, in Xcode for the iPhone.
I have a method in main.m:
int main(int argc, char *argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleas开发者_开发问答ePool alloc] init];
//I want to call the method here//
int retVal = UIApplicationMain(argc, argv, nil, nil);
[pool release];
return retVal;
}
static BOOL do_it_all () {
//code here//
}
How do I call the do_it_all method from main.m?
You can call it normally, so long as you've already declared the function before you call it. Either move the function definition above main()
or add the following line above:
static BOOL do_it_all ();
Personally, I think the former is easier, but if you have circular dependencies between functions, it can be impossible to resolve without function prototypes.
When you do add function prototypes in C/Objective-C/etc. they are frequently in a header (.h
) file, but if everything is in main.m this is probably overkill.
Like this:
do_it_all();
It's just an ordinary C function call. But you will either need to move the declaration of do_it_all
before main
, or forward declare it; otherwise, main
won't know what you're talking about.
精彩评论