72

I'm using Xcode 4.3 for Objective-C development. One feature that I like in other text editors (I know Xcode is an IDE), is jumping to a method definition within the same code file.

For example if I'm in @implementation of Calculator and calculator has 10 methods, I will like a way to jump between them.

If I press command+L I can jump to a specific line number, is there a way to jump in a similar way but to a method definition? e.g. instead of typing the line number to type only the beginning of the method name.

Can I open somehow a dialog box, type the beginning of a method signature and see instantly the search results and If I pick one method it will get me to it?

Is there a way to jump from a method to the next one?

Michael Mullany
  • 30,283
  • 6
  • 81
  • 105
  • To my best knowledge, there is no such feature. The method list box is the closest thing you can get afaik. – Tafkadasoh Sep 28 '12 at 12:26

5 Answers5

174

I think this is what you're looking for:

Type ctrl-6 to activate the "Show Document Items" in the "Jump Bar". Then start typing part of the method you are looking for to narrow the results.

Example:

To jump straight to - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

Type ctrl-6, type "cellFor", arrow down so the method is highlighted, and press Enter. The Editor will jump right to that method.

Incidentally, you can use ctrl-1, ctrl-2, ctrl-3, etc. to access the different sections of the "Jump Bar".

Pang
  • 9,564
  • 146
  • 81
  • 122
lancejjohnson
  • 1,768
  • 1
  • 11
  • 5
  • 4
    This saved my future self from rheumatoid arthritis. Much appreciated. – Pacu Nov 16 '14 at 17:56
  • If I wanted to insert the `cellForRowAtIndexPath` method into my code, what is the quickest way of doing it? Any shortcuts for using less key strokes? – mfaani Apr 20 '16 at 19:53
  • in Xcode, to just move to the next method/function it is an incredibly *cumbersome* key sequence to ctrl + 6 then ↓ then return instead of a simple option + command + ↓ – Cerniuk Jul 01 '19 at 16:51
  • If this is the only way, Xcode is a horrible IDE. – Gary Allen Sep 12 '22 at 09:36
23

If I understand you correctly, try Command-Shift-O. It also doubles as a file finder.

Archagon
  • 2,470
  • 2
  • 25
  • 38
  • 1
    I'm using that feature, but your answer doesn't relate to my question. –  Mar 21 '12 at 21:42
  • 2
    This is my favorite, but is there something like this that only finds methods in the open file? – inorganik Aug 07 '14 at 17:16
  • 1
    @inorganik Thats the method navigation bar, suggested by luddite . Ctrl + 6 – GoodSp33d Aug 30 '14 at 08:32
  • I wish there was a way to combine Command-Shift-O and Ctrl-6. The way Sublime Text handles navigation is WAY better than Xcode – lewis Dec 02 '16 at 02:19
14

Perhaps I'm not understanding what you need, but it seems like you have a couple of options.

  • Control+Command+J should take you to a definition.
  • Control+Command+Up/Control+Command+Down will toggle between .h/.m files.
  • While in the .m file, I use the dropdown for the methods often.
Pang
  • 9,564
  • 146
  • 81
  • 122
Evan Anger
  • 712
  • 1
  • 5
  • 24
  • I'm looking for jumping to methods in the same file. I've just added more details on my question. –  Mar 21 '12 at 21:40
2

If you want to press a command key sequence like Command + Option + to jump to the next method, or Command + Option + to jump to the previous method, there is no such animal in Xcode. Prior macOS development tools had such a capability, but Xcode is seriously lacking in the basics...

The fastest jump back and forth in methods in a source file is to perform a Command + F (Find) on [\-\+][ \t]*\( as a regular expression. Then you can Command + G (Find Next) to go to the next method or Command + Shift + G (Find Previous) to go to the prior method.

If you are disciplined in your method definitions, you might be able to search for - ( or + ( as a normal text string instead... a tad faster.

If this is a serious itch to scratch, maybe it is worth creating an Xcode plugin (as silly as this sounds for such a basic feature)... and post a link here for the rest of us ;-)

Cerniuk
  • 14,220
  • 2
  • 29
  • 27
1

Select a symbol (could be a method, but doesn't have to be) and right-click (or control-click). The contextual menu that pops up has a "Jump to definition" command. Control-command-J is a shortcut for that.

If the thing you're looking for isn't visible, you can use the Search Navigator (Command-3) to search through the code.

Depending on what you're looking for, you may also find the Quick Help feature in the Utilities panel helpful. If you select a symbol, Quick Help will give you at least some basic information about that symbol. For symbols in the iOS or MacOS X API's, you get quite a bit of help. If you've selected your own symbol, it'll tell you where that symbol is declared, and you can click on the file name to jump to the declaration.

I don't think there's a command to jump to the next method (where in the method would you want to jump to?). If you have a need for that sort of thing, you might find Xcode's code folding features useful. You can fold an entire method or just some of the blocks within the method. Very helpful for getting the lay of the land when you're looking at a large file for the first time.

Caleb
  • 124,013
  • 19
  • 183
  • 272
  • I've added more details to my question. I only want an easy way to navigate between a class methods in Xcode. –  Mar 21 '12 at 21:43