In console applications there generally is a main file where you type up what you want your program to do. In event-driven GUI programs, you have event handlers for each function (such as in Visual C# Windows Forms).
In Cocoa GUI applications, I don’t see a centralized place where I can make variables and run commands. For example, I can make a new class and define all its member functions and data, but I don’t have a place to actually make a new object of that class. Where do I put my “actual program”? I cannot find a file where all parts of the program are put together, I only seem to be able to define classes. A main file and function exists, but they aren’t supposed to be used — main() just starts up the application.
How does this work? Where do I put my program’s code?
Cocoa is an event driven environment, in many ways like .NET. In the vast majority of cases, the system will call you rather than you calling it. So like in your experience with C#, you’re going to hook into various places and wait until you’re called.
There are two main places you’re going to put your startup “things.” First is the Storyboard or main nib file (Storyboards are new in iOS 5). Any objects you create in your main nib file (or Storyboard) will be automatically created when the program starts. They can then respond to methods like
awakeFromNibandviewDidLoad.The other major place to kick things off is in the application delegate. This is not the home for all your program, but it is generally the first piece of “your” code that gets run. In particular, you want to add startup code to
applicationDidFinishLaunching:withOptions:.Before you go any further, I recommend you spend some time in the iOS Starting Point document. If you want to skip ahead a little, you can go to the iOS App Programming Guide. (I assume you’re asking about iOS because most people do these days. If you want Mac, it is very similar. Start with Your First Mac App.)
Apple documentations tends to be extremely good once you have a feel for where things are. And Cocoa is incredibly consistent (again, once you have a sense of what it’s going to be consistent with). Make sure to read the documents labeled “Programming Guides” rather than just the Reference docs. And when you read the Reference docs, make sure to read the paragraphs at the top. If you just jump into all the method explanations, you’ll skip most of the useful information.