Home » Swift » “Jump to definition” for methods without external parameter names

“Jump to definition” for methods without external parameter names

Posted by: admin January 9, 2018 Leave a comment


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.)


You have to do some work:

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

Use initializer expression, then cmd + click on it.