milgra
about
articles
projects
blogroll
bit-101
coding horror
blameit
failblog
beszeljukmac
sghu
navigation
posts
docs
admin
|
2010-01-15 The minimal iPhone application
January 15th, 2010
|
"Keep it as small and simple as possible" - me, all the time
Xcode, New Project -> Application -> Window Based Application, name it Minimal, and Save.
What you see in xcode now is the plain iphone application. But there are still too many unnecessary things there. We are real programmers, we won't need the interface builder descriptor, so right click on MainWindow.xib, select delete, and move to trash. Open Minimal-Info.plist as plain text file, and delete the last key-string node from it ( with MSMainNibFile and MainWindow ).
Let's remove Coregraphics.framework from frameworks, we don't need it. Right click on it, delete, move to trash.
Let's check main.m. Delete NSAutoreleasePool initialization and the release lines, we are real programmers, we want total control, not autorelease sh*t. :) Without these two lines we can simplify this function, move UIApplicationMain init after return, and remove UIKit import from the top, its already in the prefix header. We also have to tell UIApplicationMain which is our Delegate class. The result should look like this :
int main ( int countX , char *wordsX[ ] )
{
return UIApplicationMain( countX , wordsX , nil , @"MinimalAppDelegate" );
}
Let's check MinimalAppDelegate.h. Delete the @property line, we don't want to set, get and synthesize the window. Also remove UIKit import.
MinimalAppDelegate.m comes. Remove @synthesize window. Let's create it "manually". Normally it is synthesized based on the interface builder file, but we deleted that.
Let's create an UIWindow instance with the screen's dimensions :
window = [ [ UIWindow alloc ] initWithFrame : [ [ UIScreen mainScreen ] bounds ] ];
The result :
@implementation MinimalAppDelegate
- ( void )
applicationDidFinishLaunching : ( UIApplication* ) application
{
window = [ [ UIWindow alloc ] initWithFrame : [ [ UIScreen mainScreen ] bounds ] ];
[ window makeKeyAndVisible ];
}
- ( void )
dealloc
{
[ window release ];
[ super dealloc ];
}
@end
You can debug and run the application. Let's check the project's folder. We have three files in the root, the prefix, the plist and main.m, and two files for MinimalAppDelegate class under classes folder. If you do a release build, you will find that the size of the binary is 17704 bytes, so this seems the minimal size of a compiled application, of course you can short it with one-char method and attribute names, but it won't be readable then, so it won't be that simple to work with, and our first and only rule would be harmed.
Here is the link to the project source.
MilGra
|
|