Is an Objective-C Minifier Possible?
My coworker-friend-buddy, Sean, and I are putting the final touches on our iPhone framework, iBoost. One thing we have to think about now is how it will integrate with our (and your) applications. There are two basic strategies I’ve seen:
- Copy the source code into the project. This is never done with Java projects, but is always an easy choice for C-based systems because compiled code is platform dependent. This is a very common choice for small classes, too. I make a lot of my mini-modules available this way.
- Compile as a library and copy header files. This involves distributing as a compiled library with header files. Flurry does this, as well as AdMob. The obvious motivation is to keep the source a secret.
Obviously, if wee distributed iBoost as a library, it wouldn’t be to keep the code secret (since it’s open source), but it’s still a valid way to go.
I lean towards the former. Dumping the source into your project may seem messier, but if you keep it isolated in a directory instead of copying it to your Classes, it’s really no different than library distribution. Plus, as the SDK iterates, and different platforms become available, you don’t have to worry about updating your libraries all the time. I just recently had to do this with the Acapela Text-to-Speech library and it was doubly painful because they are located in France and I needed it immediately. :-)
But now I have a new thought. It seems messy to distribute source as a large group of files. I’d love to make it a two-file (*.h and *.m) distribution. Hell, one would be great if it’s doable. But how?
So, it is possible in Objective-C? I can’t find any references to it. No one seems to have done it. My guess is it’s doable. Here’s my theory on how it could work:
- Append all of the header files together.
- Pull out #import’s referencing any of the files themselves.
- Add forward references (@class) for all classes at the top of the file. (No need to ull existing ones unless we want to keep the file size minimal, which is not necessary.
I’m going to attempt it this week with a Python solution. I’ll let you know the results. What do you think?