Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xcode method navigation

Tags:

xcode

In Xcode 4, I can press Ctrl-6 to get a list of all the methods in the current file.

The problem is, if I have private methods declared at the top of my implementation file, say:

@interface Foo ()

-(void)tap:(id)sender;

@end

@implementation Foo

...

-(void)tap:(id)sender
{
  ...
}

then starting to type "tap" while the method list is visible will just take me to the declaration, since it comes first in the file, when what I really want is the implementation.

Is there any way to exclude these declarations from the method list or do I need to resort to separate Foo.h and Foo+Private.h headers?

Thanks!

like image 896
Bill Avatar asked Mar 19 '11 00:03

Bill


3 Answers

I don't think there's a way to exclude the method declarations from the Document Items popup.

If you get in the habit of using code folding, however, you might not rely so much on that popup to navigate your source code. There are commands for folding both methods and comment blocks, and you can fold all methods with one quick shortcut (command-option-shift-left arrow to fold, -right arrow to unfold by default, though you can of course customize the keys). See the Editor->Code Folding submenu for a complete list of related commands.

When you fold all comments and methods in a .m file, almost all you're left with is a list of methods that's makes it easy to find what you're looking for. You can then unfold just that method or all methods with another keystroke. It's a little strange to see all your code disappear when you first start using folding, but it's a very handy feature.

like image 198
Caleb Avatar answered Sep 18 '22 13:09

Caleb


You dont need to declare you private methods and you wont get a warning by default anymore. So one options is not to declare a prototype at all.

Otherwise as curthipster mentioned ctrl-6 is a good shortcut. I use this all the time (no mouse needed):

  1. Press ctrl-6
  2. Type the first few letter of the method name (or a word it contains and you dont even have to spell it spot on, the search filter is very good!)
  3. Tap down until the method is selected.
  4. Tap enter

Alternativly open the assistant with cmd-alt enter (to close use cmd-enter, see more shortcuts here). You can make the assistant editor look at the same file, so it has one part of view at the top and one at the bottom for example.

like image 33
Robert Avatar answered Sep 22 '22 13:09

Robert


Usually, it's better to add a named category for the private methods:

#import "Foo.h"

@interface Foo( Private )
    - ( void )tap: ( id )sender;
@end

@implementation Foo( Private )
    - ( void )tap: ( id )sender
    {}
@end

@implementation Foo
    ...
@end

Then you'll see each one. It may not answer your question, but at least you'll see your method.

One thing is also to organize your methods with mark pragmas:

#pragma mark - Private methods

May help you to navigate through the completion dialog... Hope this helps...

like image 36
Macmade Avatar answered Sep 18 '22 13:09

Macmade