In Objective-C we have method names like 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 the name of this method simply application
since everything else are just parameters? Or is it called application didFinishLaunchingWithOptions
with a space in the name?
I was looking for an official answer in the Apple Documentation but I could not find one.
For method names, start with a lowercase letter, and capitalise the first letter of embedded words.
Methods are functions that are associated with a particular type. Classes, structures, and enumerations can all define instance methods, which encapsulate specific tasks and functionality for working with an instance of a given type.
Swift inout parameter is a parameter that can be changed inside the function where it's passed into. To accept inout parameters, use the inout keyword in front of an argument. To pass a variable as an inout parameter, use the & operator in front of the parameter.
Functions are the properties of structured languages. Methods are the properties of Object-oriented language. It is a self-describing piece of code. It is used to manipulate the instance variable of a class.
The method is indeed called application
, however didFinishLaunchingWithOptions
is an external parameter name and:
If you provide an external parameter name for a parameter, that external name must always be used when you call the function.
Since there can be two functions called application
with different external parameter names, we always have to specify the external parameters when referring to a function. So, the whole name of the function/method would be
application(_:didFinishLaunchingWithOptions:)
You are right there hasn't be any convention made yet for referring to Swift functions. The safest way to refer to a function now is to use the Obj-C convention.
application:didFinishLaunchingWithOptions:
Which is still used in all Apple documentation links.
This convention is used throughout Apple documentation.
The method is indeed “just” application
.
Swift uses this more often, if you have a tableview
for example almost all functions start with tableview
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {}
The parameters “define” the functions instead of the method.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With