Cocoa Crunch (Day 2)

Continuing with a refresher crash-course in Cocoa, courtesy of Aaron Hillegass’ “Cocoa Programming for Mac OS X, 3rd Edition.” Five chapters a day for one week; so far, I’m on schedule.

Interface Builder is confusing

This came to light while working on Chapter 6, “The NSTableView and Its Datasource”. Understanding where the wiring for different elements is within Interface Builder can be confusing. Let’s say I have an NSTableColumn bound to an NSArrayController which has its content array bound to my File’s Owner which has a Class Identity of “MyClass” and contains an array of “MyObject”. This chain is already unwieldy and its creation requires jumping between various panels of the Inspector, depending on the object.

Despite having set up this chain of bindings, at no point does any option appear that shows me Interface Builder understands what I’ve done. When choosing the model keypath for my NSTableColumn binding, it only shows me the things that I MANUALLY input into the NSArrayController’s attributes panel’s “Object Controller” Class and Keys. Why wasn’t this information available as a pulldown menu option upon setting the binding for the NSArrayController?

Too many options that are related by intent are divided by type in the interface.

Xcode’s new documentation viewer is disappointing

Maybe I just need to tweak Preferences, but I’m finding the doc viewer is getting in my way. Option-double-click on a class name in the code brings up a contextual popup explaining the reason for the class’ existence. Typically I want to jump immediately to the docs to see what kinds of things I can do with the class. Now I have to click an extra “Documentation” icon in the popup to get to where I want to go.

Bookmarks are hidden in the bookmark menu, rather than on-screen at all times as they were with the previous doc reader, so I’m making duplicate bookmarks by accident. Searches seem quick, but I get repeating items that are apparently coming from two different doc sets. There is nothing to distinguish which result came from which set.

Lastly, the formatting of the documentation itself causes a lop-sided three-column layout of search results / documentation contents / documentation page. Sometimes the documentation page contains a bold, blue bar with large type at the top, further subdividing the page into a clutter of chunks. There is a level of ambiguity to the layout that I find disconcerting, an inefficient use of the window space, and worse yet an impedance toward quick grokking of researched subject matter.

The trick I learned for sorting a simple array of NSStrings

We want to click on a table header and sort an array of NSStrings (this comes from Chapter 8, “Add Sorting”). If we have an array of objects of a custom class (i.e. – Person), we can give a key path (.personName) for the NSSortDescriptor to sort an NSTableColumn on. However, it is not immediately obvious what the key path would be for an array of NSStrings, or NSNumbers. We don’t have to ask the personName (an NSString) for some further key path, so what “path” do I take to reach the objects in a simple array?

I did not find it immediately obvious that the method calls on Foundation objects can themselves be regarded as key paths. For a simple array of strings, as NSString has a “description” method that “returns the receiver”, we can use “description” as our key path. Also, as everything derives from NSObject, which has a “self” that “returns the receiver”, we can also use “self” as our key path. In the above example, we simply talked directly to “personName”, which is an NSString. We didn’t have to use personName.description, and so this trick was a bit obfuscated for me.

NSInvocation and NSUndoManager are awesome

I just want to say that the NSInvocation + NSUndoManager combination remains awesome and reminds me of why I enjoy programming in Objective-C with the Cocoa frameworks.

I’m having FUN

Out of sight, out of mind. So Cocoa has been for the past few months and it was easy to forget how much FUN I have writing programs in Cocoa. The five chapters a day is definitely a LONG day (10-12 hours per day, thus far), but it is also a great feeling of accomplishment and boy do I feel smart when the day is done. I do think this is about the last time I can force myself to do Aaron’s “RaiseMan” project again, but it is nice to leave it on a high note.

Leave a Reply

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