开发者

Xcode method navigation

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开发者_如何学Go 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!


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.


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜