7

For method calls with external parameter names I can cmd-click in Xcode on any parameter name to jump to the method definition. For example, in

let a = Array(count: 3, repeatedValue: 0)  

a cmd-click on "count" or "repeatedValue" jumps directly to the Array initializer method

init(count: Int, repeatedValue: Element)  

However, I haven't found a way to do the same for methods calls without external parameter names, as in

let c = Array("abc".characters)

Of course I can lookup that the characters method returns a String.CharacterView which in turn conforms to SequenceType, so this will call the Array initializer

init<S : SequenceType where S.Generator.Element == _Buffer.Element>(_ s: S)  

but I wonder if somebody has found a direct "jump to definition" method for this situation.

This would be very useful if a type has many overloaded init methods (without external parameter names), to determine which one is actually called.

The above examples are from Swift 2/Xcode 7 beta, but the problem is not tied to a special Swift/Xcode version.

(Also posted at the Apple Developer Forums: https://forums.developer.apple.com/thread/12687.)

Martin R
  • 529,903
  • 94
  • 1,240
  • 1,382
  • Can you not click on "Array"? I've never even thought to click on the parameters names and always clicked on the part outside the parens. (I guess in this case, it just goes to the class declaration and not the specific initializer.) – nhgrif Aug 17 '15 at 13:07
  • @nhgrif: Exactly, cmd-click on "Array" jumps to `public struct Array : ...`, that is not what I am looking for. – Martin R Aug 17 '15 at 13:10

1 Answers1

6

You have to do some work:

let c = Array.init("abc".characters)
//           ^^^^^

Use initializer expression, then cmd + click on it.

rintaro
  • 51,423
  • 14
  • 131
  • 139