Reputation: 25
I'm new to IOS and objective C. The following method declaration shipped with UIApplicationDelegate is confusing me:
- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions;
According to the introduction from Apple official site, the method name should be didFinishLaunchingWithOptions which accept 2 parameters, application and launchOptions.
But based on my limited knowledge, I thought the method is named application which accepts 2 parameters, applications andlaunchOptions. Can anyone help me understand this method declaration?
Shouldn't the first string right before the first column represent the method name?
Upvotes: 1
Views: 96
Reputation: 13514
- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions;
In the above case:
Method name -- applicationdidFinishLaunchingWithOptions
-
means instance method, +
for class method,
(BOOL)
is return type of the method,
application:(UIApplication *)
is the application object itself,
(NSDictionary *)launchOptions
is the arguments
Upvotes: 0
Reputation: 27428
You can consider left portion of colon (:)
as name and right portion as parameter, and when there are multiple parameters, method name should be produce by all left portion join by colon (:)
. So in,
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions;
application:didFinishLaunchingWithOptions:
should be method name, and application
and launchOptions
which stand at right side are parameters.
Objective - C
is a descriptive language
so that it's syntax(method name) should be written as anyone can get idea that what this method will do and what parameters are. So, for understanding purpose you can said that method name is didFinishLaunchingWithOptions
because this sentence gives meaning of method but technically method name is application:didFinishLaunchingWithOptions:
. And we should also follow this protocol(write method name as it describe purpose of method and parameters) when we are writing our custom methods!
And ideally first parameter should be instance of class of method, If method is containing instance of class
as parameter
!
Upvotes: 0
Reputation: 6566
the name of this protocol message is:
application:didFinishLaunchingWithOptions:
Upvotes: 0
Reputation: 1336
Please refer to this official documentation on how to declare methods in iOS (using Objective-C).
Note : Look from the section 'Methods Can Take Parameters'.
List of it -
1) Method with no args
-(void) methodWithNoArgs
2) Method with 1-argument
-(void)methodWithOneArgument:(NSString*)argument1
3) Method with multiple-args
-(void)methodWithMultipleArguments:(NSString*)argument1 Arg2:(NSString*)argument2 Arg3:(NSString*)argument3
Here, "methodWithMultipleArguments,Arg2,Arg3" form multiple parts of the method name.
Upvotes: 1
Reputation: 224
1). Every app begins with UIApplicationDelegate -application:didFinishLaunchingWithOptions: (or more accurately, -application:willFinishLaunchingWithOptions:, when implemented). It is called by the application to notify its delegate that the launch process is finishing, and nearly ready to run.
2). Determining why and how an app launched is the responsibility of the launchOptions parameter. Like a userInfo dictionary, -application:didFinishLaunchingWithOptions: can get information for particular named keys in launchOptions.
3). Many of these keys are also available in the UIApplicationDidFinishLaunchingNotification notification posted on application launch. Check the docs for additional details.
4). Numerous as they are, launchOptions keys can be more easily understood when organized into groups, corresponding to why the app was launched.
Upvotes: 0
Reputation: 769
Method name is application:didFinishLaunchingWithOptions:
And parameters: application
and launchOptions
Upvotes: 0
Reputation: 3726
This method is named application:didFinishLaunchingWithOptions:
and it takes 2 parameters: application
and launchOptions
.
Note that semicolons are included in the method name.
The name is not limited to the part before the first argument, every part before an argument name is also included. It thus creates very long method name but it also makes the language easier to read.
Upvotes: 0