Is an Objective-C Minifier Possible?
Join the DZone community and get the full member experience.Join For Free
my coworker-friend-buddy, sean, and i are putting the final touches on our
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
- 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?
Published at DZone with permission of John Blanco, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.