I'm curious, what role does the int main function play in a Cocoa program? Virtually all of the sample code I've been looking at has only the following code in main.m:
#import <Cocoa/Cocoa.h>
int main(int argc, char *argv[])
{
return NSApplicationMain(argc, (const char **) argv);
}
What exactly is this doing, and where does the program actually start stepping through commands? It seems my conceptions need readjustment.
Cocoa solid, cocoa butter, and chocolate are all rich sources of antioxidants. 2 Epidemiological studies show an inverse association between the consumption of cocoa and the risk of cardiovascular disease. 3, 4 The likely mechanisms are antioxidant activity; improvement in endothelial function, vascular function,...
Cocoa products are used extensively in the food and pharmaceutical industries. Cocoa powder and cocoa butter are often mixed with chocolate liquor (ground cacao seeds), sugar, milk, and other flavors.
Uses and Pharmacology. Cocoa has been reported to be a source of natural antioxidants, 10 the free radical scavengers that preserve cell membranes, protect DNA, prevent the oxidation of low-density lipoprotein (LDL) cholesterol that leads to atherosclerosis, and prevent plaque formation in arterial walls.
Clinical data. Numerous intervention trials have shown that consumption of flavanol-containing cocoa products can improve endothelial function 41, 43, 44, 45, 46 vascular function 44, 47, 48 and insulin sensitivity 47; as well as attenuate platelet reactivity 46, 47, 49, 50, 51, 52 and reduce blood pressure.
Since a Cocoa project starts like any other, the entry point for the Operating system is main. However the Cocoa Architecture is constructed to actually start the processing of your program from NSApplicationMain, which is responsible for loading the initial window from your application and starting up the Events loop used to process GUI events.
Apple has a very in depth discussion on this under the Cocoa Fundamentals Guide : The Core Application Architecture on Mac OS X
If you want to learn how control passes from "launch this" to the main()
function, the execve man page has the details. You would also want to read about dyld. main()
is a part of the Unix standard. Every single program that you can run effectively has a main()
.
As others have mentioned, NSApplicationMain
passes control to Cocoa. The documentation is quite specific as to what it does.
One interesting note, NSApplicationMain
doesn't actually every return. That is, if you were to separate the call to NSApplicationMain
from the return in your main
function and put code in between, that code would never be executed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With