Structure and Interpretation of Computer Programmers

I make it easier and faster for you to write high-quality software.

Wednesday, January 23, 2008

How to solve every problem in Cocoa

Yes, really, every problem. Don’t think of Cocoa as "simple things simple, complex things possible" (actually, was it Cocoapenextstepsody or Perl who started with that tagline? Or someone else? I digress) but "simple things simple, complex things simple but you’re looking at it wrong". With Objective-C 2.0 (particularly properties), Core Data, Cocoa Bindings and Cocoa Scripting, almost every "it doesn’t work" moment comes down to getting something wrong with KVC or with KVO – either observing the wrong key, or typoing a method name such that you aren’t KVC-compliant for a key you need to be, getting validation wrong or unexpectedly going down the -setNilValueForKey: path. So do yourself a favour:

#define GLInstanceMethodEntryLog(format, ...) NSLog(@"-[%@(%p) %@] entry: %@", NSStringFromClass([self class]), self, NSStringFromSelector(_cmd), [NSString stringWithFormat: format, ##VA_ARGS])

Now because all of the retain count bugs disappeared when you turned the garbage collector on, the remaining issues are with that bit of code the PHBs are paying for ;-)

posted by Graham Lee at 23:30  

1 Comment »

  1. ‘Twas Perl.

    Comment by Anonymous — 2008-02-06 @ 03:18

RSS feed for comments on this post. TrackBack URI

Leave a comment

Powered by WordPress