I come from c++/c#/java camp and am confused when I see the following objective-c syntax…
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:
(NSDictionary *)launchOptions { }
from what I understand it goes (return type)functionName:(param type)param; like the following
- (void)applicationWillResignActive:(UIApplication *)application { }
whats with the parameter (UIApplication *)application didFinishLaunchingWithOptions?
In Objective-C the parameters are part of the method signature. The selector for the method you describe would be
application:didFinishLaunchingWithOptions:. This comes from Smalltalk, and while it may make the method declaration harder to read, it makes the code actually easy to read:As you can see, the resulting calling code looks as if you were reading a phrase.
As for the
UIApplicationparameter, that’s a design choice you’ll see throughout Cocoa. All the methods in a delegate will receive as its first parameter the object they are delegates of. This makes allows you to reuse a delegate, and have its logic depend on the object they are the delegate of.In this case, you could use the same
UIApplicationDelegatefor differentUIApplicationinstances, and have its code be conditional based on someUIApplicationparameters.