A bit of Code Completion Kung Fu
Hi everyone!
Some time ago we had a post about basics of code completion with AppCode, so I’ll assume that you already are familiar with it, and that you have ⌃Space and ⌃⇧Space shortcuts at your fingertips. You know how and when to invoke completion, but let me ask you a question. What do you do when you’ve found the required item in the list? Wait, here’s a wild guess, you press Enter. Right? That works, of course. AppCode inserts the selected element at the caret position. However, there is a number of scenarios when AppCode can do more than that, look deeper into your code structure and in the end save even more time for you.
In short, there are two more ways to finish code completion: you can either use Tab, or one of the symbols like a dot, colon, semicolon or a bracket. What difference does it make? Let me just show you some examples.
Finishing with Tab
It doesn’t matter which type of completion you use, the finishing logic described here will work the same way for both of them. When you press Tab instead of Enter on the selected item, instead of just inserting the element, AppCode overwrites the following expression with the selected option, taking the structure around into account.
For instance, let’s say you have a method call that you want to replace with another method call:
Here’s what happens when you use Enter:
Note, that selected item is simply inserted, and you still need to clean up what’s left from the previous call. But here’s what you’ll get by pressing Tab:
Neat, hah?
Less manual work, and more intelligent result. Basically, completion with Tab is a structural completion. Try it out on selectors, variables, methods to get a better feeling of it.
Finishing with a symbol
Here, by symbol I mean a dot, a colon, a bracket… Finishing completion of an element with one of those characters also completes the statement.
So you invoke code completion:
If you press Enter, you get what you were aiming for, but the statement isn’t finished yet:
If you press a dot, having an item selected in the list, you jump to the next completion suggestion:
You can also finish completion with a semicolon to complete the statement at once:
If you play a bit with these various ways of completing your code, I believe you’ll find more uses for them, and also get a feeling when they work better for you.
There are more code completion (and not only) tricks to come, so stay tuned!