I\'m trying to understand how the things in Cocoa works but I\'m struggling with one thing. I saw http://cocoawithlove.com/2010/09/minimalist-cocoa-programming.html and http
That was me six months ago! I did not find a decent tutorial either but started with a new project using the default Xcode project template:
I started out with the setup Xcode generates for you when you start a new project and implemented piece by piece as I went along. There's some good reading here on Stackoverflow about the use of the various controller classes but here's what I did:
I am by no means an expert, so I stand corrected for better approaches but so far this setup has been easy to work with, easy to maintain and easy to extend.
Note: Using Core Data is optional but over time I've come to love it and think it's very powerful and a huge time saver. When you decide not to use Core Data, the above setup will still work but you will have to manage your own data.
EDIT: This post explains the relevance of NSDocumentController.
EDIT2: This one from Apple is an interesting read as well.
EDIT3: You do need NIBs (or XIBs as they're now called) as they contain the UI of your app. You pull them in via a view controller (subclass NSViewController
):
NSString *aControllerName = [anIdentifier stringByAppendingString: @"ViewController"];
NSString *aNibName = [anIdentifier stringByAppendingString: @"View"];
Class aControllerClass = NSClassFromString(aControllerName);
[self setCurrentController: [[aControllerClass alloc] initWithNibName: aNibName bundle: [NSBundle mainBundle]]];
In the above anIdentifier
could be Department
, which would instantiate the DepartmentViewController
and load the XIB name DeparmentView
.
You can use plists to store your data but that's not a requirement. There are many ways to store your apps data. You'll have to read about the various architectures Apple has in place and make your own choices.