I’ve recently been working on a static library for distribution to other developers — Audiobus — and I need to include a couple of graphical resources with the distribution. The usual solution to this is to include the resources separately in a bundle, and require the user to drop them in to their project along with the static library.
I thought I’d see if I could make the process just a little neater, and successfully devised a way to compile the images straight into the library, so the distribution remains nice and clean — just the library itself and a few header files.
Now, I can pop image resources into a folder, and after compiling, access them within the static library with:
UIImage *image = TPGetCompiledImage(@"Button.png"); |
It automatically handles “@2x” Retina images (although it doesn’t currently do “~ipad” versions).
Here’s how it’s done.
The magic is in a shell script which uses the xxd
hex dump tool to create C code that represents the image data as a byte array, then creates around it a set of utilities to turn those arrays into UIImages on demand.
Along with it is a couple of template files — a header and implementation file — that describe the format of the derived code.
Finally, a little tweaking of the project in Xcode (with a brief foray into a text editor to work around some Xcode shortcomings) puts it all together. Read More
Searching iOS header files with Xcode
I’m often having to grep through various iOS frameworks in search of error codes that appear (“What the bloody hell does -10867 mean?”). This can be a bit annoying – especially while working with Core Audio – so I put together an Alfred workflow that does it for me.
Here it is – type “hs” (short for “header search”) then the text you want to search for, and it’ll give you matching results. Hit enter to open that file:line combination in Sublime Text, or edit the action script to work with the editor of your choice.
Search Xcode Header Files.alfredworkflow