Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Code completion for multi-parameter method names in Xcode 4

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.

like image 375
John Whitley Avatar asked Jul 13 '11 01:07

John Whitley


2 Answers

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.

like image 93
Bartosz Ciechanowski Avatar answered Sep 25 '22 09:09

Bartosz Ciechanowski


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.

like image 39
an0 Avatar answered Sep 22 '22 09:09

an0