Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

void main method in an implementation section of the class

I saw a class (inherits from NSOperation class) with .h and .m files as usual, but in the implementation section there is -(void) main method and NSAutoReleasePool object, it looks like the main method of the application itself, why there should be a method with this name in a .m file ?

like image 864
JAHelia Avatar asked Dec 27 '22 10:12

JAHelia


2 Answers

It is just a method on NSOperation. The difference is:

int main (int argc, const char * argv[])

Is a C function which is where the program starts

- (void)main;

Is an objective-C instance method on a class.

The reason it has it's own auto releasepool is that it is generally called on a separate thread therefore this new thread needs to deal with auto released objects.

like image 190
Paul.s Avatar answered Feb 19 '23 14:02

Paul.s


Maybe it's a NSThread or NSOperation subclass? They have their own main() methods.

like image 29
Kirby Todd Avatar answered Feb 19 '23 15:02

Kirby Todd