Down with Magic Strings! (Permalink)
I recently linked to KSImageNamed as a solution to the issue of auto-completion and of image resources. Today I came across Patrick Hughes' script to generate image aliases as part of the build process.
Each time it runs it scans a folder for images. It then compares the image names to collect the various platform specific and scaled versions and groups them together. It then #defines a block for each group that loads the image using imageNamed:, throws an assertion if the image doesn't load and then returns the image.
I think I like this one even better, since it also validates the the image resources and points out missing Retina or iPad assets where appropriate.
Cocoa is unfortunately fairly stringly typed and the more we enforce at compile-time, the fewer errors can happen at run-time.
Posted in ❤ing