Cocoa Programming for Mac OS X (Ch 13-16)

I’ve been busy at work so haven’t made as much progress in the book as I wanted, the chapters I did cover however were great!

Chapter 13, User Defaults.

In chapter 12 a preference screen(panel) was introduced, a preference menu item is standard in a default application. In OS X preferences are automatically stored under ~Library/Preferences. To access them you can use the NSUserDefaults class which has a standardUserDefaults method and returns an NSMutableDictionary. When the application starts you need to enter your defaults in that dictionary and call the registerDefaults method. Any changes the user makes are persisted to the location stated above, just make sure whatever you put into it can serialize itself. In the rest of your application you can just read or set values in that dictionary it’s automatically saved.

In .Net you’d use user specific application settings which are stored in the app.config.

Chapter 14, Using Notifications.

Something which is definitely missing in the .Net framework is a Pub/Sub mechanism. There is one available in the EnterpriseLibrary and in Spring.Net but it’s great to see this in Cocoa. Every running application has an instance of NSNotificationCenter, an observer can ask to be notified of certain events, certain events of a certain object or all events of a certain object. A publisher will tell the NotificationCenter about the notification it wants to send. The NotificationCenter will look up the observers and call the method that was supplied when they subscribed. I just recently needed this in a very large application, having it at hand would certainly have saved time.

Chapter 15, Alert Panes.

In the .Net world the MessageBox.The only big difference here is that here they can be run modally, meaning no other windows will receive events until it is closed, or as a sheet, meaning it’s specific to a certain form.

Chapter 16, Localization.

Again this can be compared to the work you need to do in Visual Studio and .Net, the main difference here is that you can pretty easy extract the strings that need to be localized. This is probably possible in the .Net world too with some sort of plugin, but it’s always nice to see it build in, like the notifications.

I’m now half way through the book and can say that it’s a very pleasant one to read, you can get it here . I’ve also adjusted my view on Objective-C and Cocoa, while at first it seemed a bit rough and basic I’m beginning to see that it’s full featured language and framework with very advanced capabilities which don’t require a lot of code. Though the real challenge will be to build a real application after I’ve completed the book. I’m still staring at the screen sometimes wondering why I got three errors when there’s only a missing ) .

Oh yeah, thanks Lemmy for giving me a tilde over IM, I haven’t found that key on the keyboard yet :p.

RaiseMan – Chapter 13.zip (86.38 kb)

RaiseMan – Chapter 14.zip (87.29 kb)

RaiseMan – Chapter 15.zip (87.67 kb)

RaiseMan – Chapter 16.zip (111.13 kb)

2 Replies to “Cocoa Programming for Mac OS X (Ch 13-16)”

Leave a Reply to Donovan Zerkle Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.