Simplified Logging
I have noticed a pattern in my Cocoa code, which I have been able to simplify. I often print out the value of a variable for debugging. 99 times out of 100, the code looks like this: NSLog(@"actionURL...
View Article-description, Little-Known Hero of Debugging
Or: How to Make NSLog() Useful With Your Objects Say you have an archaically named NSArray that you want to inspect — it’s easy to do, since NSLog(@"The bestiary is %@", bestiary); prints out the...
View ArticleI Would Rather Have a Runtime Error Than a Compile Error
And the weird thing is, I realized early in my career that I would actually rather have a runtime error than a compile error. [(some laughs)] Because at that time… now this is way contrary to popular...
View ArticleCFShow is NSLog for Core Foundation Types
CFShow(coreFoundationThingy) will print out a description of coreFoundationThingy to the console. Output looks something like: {value = w:1186.000000 h:687.000000 type = kAXValueCGSizeType} If NSLog()...
View ArticleBug In The Machine
I was going through some old (OS 9 old at youngest!) backups, and found this dump from a MacsBug session. You can actually see a bug sitting in memory! To me it looks like the bug is inside an old...
View ArticleNSAssert Considered Harmful
The NSAssert() function is unreliable, and therefore dangerous. Plain-old assert() is a better choice. Note that #define NDEBUG disables assert(); and #define NS_BLOCK_ASSERTIONS disables NSAssert()....
View ArticleCatching nil Member Variables
When I wrote this method it seemed like it would be helpful, //log a warning for any member variable that nil - (void) warnOfNilIVars; { unsigned int ivarCount = 0; Ivar * ivarList =...
View ArticleDon’t Check malloc()
There’s no point in trying to recover from a malloc failure on OS X, because by the time you detect the failure and try to recover, your process is likely to already be doomed. There’s no need to do...
View ArticleWhat Am I About To Call?
Say you’re in gdb, and about to execute a call instruction for dyld_stub_objc_msgSend, how do you know what’s about to happen? On i386 (gdb) x/s *(SEL*)($esp+4) tells you the message that’s about to be...
View ArticleThe Most Useful Objective-C Code I’ve Ever Written
Actually, it’s the most useful code I’ve extended; credit for the core idea goes to Dave Dribin with his Handy NSString Conversion Macro. LOG_EXPR(x) is a macro that prints out x, no matter what type x...
View Article