Reputation: 384
I am trying to understand what 'didFinishPickingMediaWithInfo' means in the following swift function definition.
func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) {
}
I see that 'info' means dictionary collection type, but I don't get why it is preceded with 'didFinishPickingMediaWithInfo'. I am new to swift and iOS development in general please help to answer probably trivial question. Thank you
Upvotes: 0
Views: 83
Reputation: 2313
This allows you to give parameters sort of an alias to the more verbose version. So instead of using didFinishPickingMediaWithInfo
as a variable to manipulate, you will only have to use the local parameter (or alias) called info
.
Specifying External Parameter Names
You write an external parameter name before the local parameter name it supports, separated by a space:
func someFunction(externalParameterName localParameterName: Int) { // function body goes here, and can use localParameterName // to refer to the argument value for that parameter }
Upvotes: 1
Reputation: 4967
From the documentation:
Modifying External Parameter Name Behavior for Methods
Sometimes it’s useful to provide an external parameter name for a method’s first parameter, even though this is not the default behavior. To do so, you can add an explicit external name yourself.
Conversely, if you do not want to provide an external name for the second or subsequent parameter of a method, override the default behavior by using an underscore character (_) as an explicit external parameter name for that parameter.
This means that in your method, the word didFinishPickingMediaWithInfo
is the variable name used when calling the method. However, you get the data from that in the info
variable. For example, in your case, the method would be called as imagePickerController(picker: <UIImagePickerController>, didFinishPickingMediaWithInfo: <info>)
, because the didFinishPickingMediaWithInfo
substitutes the info
.
Hope that helps!
Upvotes: 1