Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Jump to definition" for methods without external parameter names

Tags:

xcode

swift

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

like image 207
Martin R Avatar asked Aug 17 '15 11:08

Martin R


1 Answers

You have to do some work:

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

Use initializer expression, then cmd + click on it.

like image 181
rintaro Avatar answered Oct 02 '22 09:10

rintaro