I'm looking at the source for: https://github.com/intabulas/ipivotal/blob/master/Classes/iPivotalAppDelegate.m
It looks like the "main" file for an iphone app, since it has a reference to the UIApplication, am I correct?
How is it that there is a .h file and in the .m file there is another block of code for the @interface with the same name?
I guess its allowed to redefine or continue the dec开发者_如何转开发laration of an interface?
You're basically correct, -[<UIApplicationDelegate> applicationDidFinishLaunchingWithOptions:]
is the entry point for an application's custom code (the real entry point is actually UIApplicationMain()
, but I wouldn't try re-implementing that if I were you).
The "second @interface
" in the .m file is a category, which allows you define extra methods that aren't defined in the class's main interface. This can be used either to break a class over multiple files, to add functionality to an existing class or (as here) to keep some method definitions private.
In general, yes, the AppNameAppDelegate class is where you put all the application-level code.
What happens below the covers is that the main()
function calls the Cocoa framework's initialization function, which loads a NIB that contains the app delegate. The UIApplication
object (supplied by the framework) will invoke methods of the app delegate at appropriate times.
You can continue defining the @interface in the .m file in a private category, this is commonly done to have private methods and properties you do not wish to expose.
精彩评论