Part I: Spawning Threads Using Selectors With Multiple Parameters

07/07/2009 3 comments

If you’ve spent much time working with thread in Cocoa, you have likely come across the following roadblock: you can only specify one parameter when spawning a new thread from a selector.  The first reaction is to rewrite your method with a single parameter that takes collection of objects and then unpacks them.  This can lead to untidy or prolix code, though, and doesn’t do anything for readability or debug-ability. You also need to know when you define your method that you will want to spawn it off–otherwise you face refactoring down the road.  At any rate, spawning via selector is a convenience method; we shouldn’t be forced to change our code in order to use it.

You can see glimmers of hope, though, as you study the problem.  Objective-C allows you to include multiple parameters in a selector, as in @selector(myMethod:withAValue:andAnother:). However, you will throw an exception at runtime since you can only specify one context object, and thus, the runtime will only have values to pass for one of the arguments. So close, and yet, so far away.  Is our only other option subclassing NSThread?  Thankfully, no.  We can have our cake and eat it, too, with just a little work on our part. The answer lies in the NSInvocation class.
Read more…

Extracting localization strings from Settings.bundle plists

07/01/2009 1 comment

If you are building child panes in your Settings.bundle, you’ll end up with several .plist files. When it comes time to localize your project, you find the creation of the corresponding .strings file a bit tedious (I know I do).

Here’s a handy list bash script which will (i) find tags, (ii) extract the contents of the following tag, and then (iii) output that value to a text file in the “string” = “string” format needed for ibtool.

Read more…