Method Names in Swift

In Objective-C, we have method names, for example application:didFinishLaunchingWithOptions: but in Swift, the method for the same job looks different.

 func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { // Override point for customization after application launch. return true } 

Is this name just application because everything else is just parameters? Or is it called application didFinishLaunchingWithOptions with a space in the name? I was looking for an official answer in Apple Documentation, but I could not find it.

+5
source share
4 answers

The method is really called application , however didFinishLaunchingWithOptions is the name of the external parameter and:

If you specify an external parameter name for the parameter, this external name should always be used when calling the function.

Since there can be two functions called application with different names of external parameters, we always need to specify external parameters when accessing the function. So, the whole function / method name will be

 application(_:didFinishLaunchingWithOptions:) 

You are correct as long as there are no Swift function reference conventions. The safest way to reference a function now is to use the Obj-C convention.

 application:didFinishLaunchingWithOptions: 

which is still used in all links to Apple documentation.

This agreement is used throughout Apple's documentation.

+7
source

The method is really a "simple" application .
Swift uses this more often if you have a tableview , for example, almost all functions start with a tableview

 func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {} func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {} 

Parameters "define" functions instead of a method.

+1
source

What does its name mean in the documentation? this is application(_:didFinishLaunchingWithOptions:) I can’t imagine the circumstances when you need to call it manually, but just in case:

  application(app, didFinishLaunchingWithOptions:aDictionary) 
0
source

Naming in both languages ​​is the same.

If you need good proof, try using any other name in the selector.

0
source

All Articles