Void main in the class implementation section

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

+4
source share
3 answers

This is just an NSOperation method. The difference is as follows:

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

Is a function of C where the program begins

 - (void)main; 

It is an objective-C class instance method .

The reason it has its own auto-release is because it is usually called a separate thread, so this new thread has to deal with automatically released objects.

+6
source

Maybe this is a subclass of NSThread or NSOperation? They have their own main () methods.

+3
source

to indicate apple docs ...

NSThread.h main

The basic entry point procedure for a stream. - (void) main discussion

The standard implementation of this method accepts the target and selector used to initialize the receiver and calls the selector to the specified target. If you subclass NSThread, you can undo this and use it to implement the bulk of your thread. If you do this, you do not need to call super.

You should never reference this method directly. You should always start your thread by calling the start method. Availability

so this is the use of main in each thread, and each thread has a resource pool for itself .. hope this helps.

+1
source

Source: https://habr.com/ru/post/1384467/


All Articles