17

In Xcode4, I'm finding that I can't get code completion to readily narrow for multi-parameter method names where the first part is common. For example, consider the following methods from UITableViewDelegate:

- tableView:viewForHeaderInSection:
- tableView:heightForHeaderInSection:
- tableView:accessoryTypeForRowWithIndexPath:
...

The list goes on; there are quite a few methods that start tableView. If I type "tableView", the list is long and not quickly navigated. If I type "tableView:", code completion is exited as soon as I type the colon (:). If I type a run-on such as "tableViewview", completion also exits, presumably as it no longer literally matches the first method name part.

Is there some way to complete via the keyboard on such a list without resorting to either mousing around or clattering out a random number of arrow key hits to navigate the long list? I'm having a hard time believing that code completion for multi-parameter Objective-C methods is so limited, but neither experimentation nor documentation have proved illuminating thus far.

Update for clarification: Above I'm referring to completion of a method declaration (e.g. in a .m file), not of a method call. For method calls, Xcode 4.x does completion for each method parameter part independently; this works great. The problem above only applys to declarations, generally when starting to write a new method implementation in a .m file.

Cœur
  • 37,241
  • 25
  • 195
  • 267
John Whitley
  • 2,030
  • 18
  • 22

3 Answers3

6

It does seems that the behavior you expect is (unfortunately) not implemented in Xcode. However, I've found a partial solution: code completion works when you specify the complete first part of the multi-parameter method, i.e. if you type this (with space at the end)

- tableView:(UITableView *)tableView 

and press ESCAPE key then the code completion dialog will appear and you will be able to keep typing the rest of the method name.

You are probably wondering:

"Oh boy, do I really have to type in this long preamble just to get my code completion?"

Code snippets to the rescue! You just have to type the preamble once and convert it into snippet. I found it's best to configure it the following way, don't forget to add space at the end of code part, it will make things easier.

Ima

How should you use the thing you've just created? In your .m file start typing tabl and Xcode will let you autocomplete the snippet for you. Once the preamble is placed press ESC to reveal the auto-completion list.

This solution is not very robust, since you have to create a snippet for every multi-part method you want to use, but it does save some time and there aren't that many multi-part method names that share the same prefix.

Community
  • 1
  • 1
Bartosz Ciechanowski
  • 10,293
  • 5
  • 45
  • 60
4

I'm annoyed by this problem for quite a long time. Now I can verify that there is no way to do even in the newest Xcode 5, I submitted a bug report:
Multi-parameter method declaration completion in Xcode

Please dup it if you also want it.

an0
  • 17,191
  • 12
  • 86
  • 136
2

Oh sorry, it does not work that way I mentioned with protocol stubs like you wanted in your update. I use Accessorizer for that, an app in the mac app store to fully implement the declaration of your delegate/protocol methods you want to implement. Hope that help a little bit.

Old post:

I use Tab for this. Example I often have: You want one of many init methods in the code completion.

Then you don't want to scroll down or use to many keystrokes to get to the right method.

Hit i > hit Tab > init is completed.

Hit Escape and then w and then again Tab for all these initWith methods.

You can even use Tab ⇥ / Escape after the first parameter, when there is more than the method with only one parameter.

In your case hit t > Tab > Escape > a and Return , there you got your third method. You can also jump to the previous code completion argument with Shift + Tab .

Binarian
  • 12,296
  • 8
  • 53
  • 84