-1
optional func locationManager(_ manager: CLLocationManager,
           didUpdateLocations locations: [CLLocation])

What is didUpdateLocations? What is the reason for using such a name? I think generally, with other methods.

luk2302
  • 55,258
  • 23
  • 97
  • 137
martinek
  • 78
  • 5

2 Answers2

1

As @KnightOfDragon already mentioned Swift differentiates between internal and external parameter names.

Consider the following example:

class Bla : NSObject, CLLocationManagerDelegate {
    func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
        print(locations)
    }
}

let bla = Bla()
bla.locationManager(someLocationManager, didUpdateLocations: [])

didUpdateLocations is the external parameter name that is used when calling the function. locations is the internal one that you use in the actual implementation.

The reason for that behavior is that when calling the method you clearly know what each parameter is used for, what the function does and you can read the call like a normal english sentence:
"The locationManager someLocationManager didUpdateLocations (to) []"

On the other hand when implementing the function you do not want to have to deal with the readable name didUpdateLocations as your variable name, but what you want to use is the locations array.

Only having one name would produce sub-optimal results since you would either have to write

print(didUpdateLocations) // ugly variable name

or

bla.locationManager(someLocationManager, locations: []) 
// what the **** is this function doing
luk2302
  • 55,258
  • 23
  • 97
  • 137
0

https://developer.apple.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Functions.html#//apple_ref/doc/uid/TP40014097-CH10-ID166

Function Parameter Names

Function parameters have both an external parameter name and a local parameter name. An external parameter name is used to label arguments passed to a function call. A local parameter name is used in the implementation of the function.

Community
  • 1
  • 1
Knight0fDragon
  • 16,609
  • 2
  • 23
  • 44
  • 2
    That is not what the question is, sounds like his code is an example of what he is looking for – Knight0fDragon Jan 19 '16 at 19:07
  • What is the name of the parameter before the method in Swift? <-- This is his question, this is what I am answering – Knight0fDragon Jan 19 '16 at 19:08
  • I do not understand the downvote neither. The reference and citation is fine and perfectly reflects what OP is asking about - I included a little bit more of explanation because I feel that is missing from this answer - but far from a reason to downvote +1 – luk2302 Jan 19 '16 at 19:29
  • I felt the quote would answer better than any way I could explain, and by explaining would just mess it up further – Knight0fDragon Jan 19 '16 at 19:31
  • 1
    Martin S, please stop choosing both as correct answers, you can only pick 1. When you get enough rep to upvote, you can comeback to this question and upvote the answers. – Knight0fDragon Jan 19 '16 at 19:34