bli1ww
Last Updated: February 25, 2016
·
305
· daij-djan

a better, unified main.m for OSX and iOS

a main.m for any case: https://gist.github.com/Daij-Djan/4969809

one main to rule them all ;)

a better, unified main.m for OSX and iOS

A main.m file is the entry point for all objective-C mac and iOS apps. In most cases it is a simple 'one liner' that start a NSApplication or UIApplication which then configures itself from the info.plist.

But that simple approach has one crucial drawback:

It demands a xib file that contains the appDelegate -- and in many cases only that! Since the iPhone 5 not even the main window is created in the xib due to the different screen sizes

--
one more issue you don't have to worry about

Writing a custom main.m file is far from rocket science but it gets annoying soon and is just one more piece of custom code!

universal main.m implementation

This main file checks the info.plist for a xibfile (NSMainNibFile), a specific XXApplication principal class (NSPrincipalClass) and a class to use as appdelegate (DDAppDelegateClass)

It then invokes apple's native UIApplicationMain or NSApplicationMain with the right parameters


a main.m for any case: https://gist.github.com/Daij-Djan/4969809