Complete Statement in AppCode

Posted on by Stanislav Dombrovsky

The are several completion types available for Objective-C in AppCode. Basic completion (^Space) is an essential IDE feature that allows you to quickly complete variable, class and method names as you type. Smart Type completion (⌃⇧Space) is more advanced: it analyzes the context you are currently working with and filters the list of methods and variables to match the expected expression type.

The latest AppCode EAP delivers a new kind of completion: Complete Statement (⇧⌘Enter). Let’s take a look at how it can speed up writing Objective-C code together with some other AppCode features.

We will implement a simple cellForRowAtIndexPath method for the UITableView in the UIViewController. First step is to dequeue the table cell and introduce the needed variable:
Step 1
Note that you do not need to care about square brackets in this case – AppCode will insert them automatically.

For this sample let’s use a formatted NSString as a unique cell identifier. Invoke Smart completion and quickly insert [NSString stringWithFormat]:
Step 2

After specifying the id, do not move the caret using the keyboard or mouse – just invoke Complete Statement, and the semicolon will be inserted automatically.

To get the cell instance, let’s create a local variable using Introduce Variable (⌥⌘V) and then use Complete Statement to quickly jump to the new line:
Step 3

As usual, we should check if the cell was already created. And here goes another use-case for Complete Statement: type if and finish completion with ⇧⌘Enter to jump into the parentheses for specifying an expression, and one more time to jump inside the curly braces:
Step 4

Complete Statement can also be used with other control statements, such as for, while, do and switch.

Invoke Smart Completion to allocate the cell and specify the cell type after it:
Step 5

Oh, wait! We need the cell identifier again, and there is no sense to have a duplicate in the code. Let’s separate it into a variable and then re-use it:
Step 6

Move the caret to the initWithStyle method, jump to the second parameter using Tab, invoke Basic Completion and finish it with Complete Statement again:
Step 7

Now we can return the cell from the method – invoke Basic Completion and finish it with Tab instead of Enter:
Step 8

That’s it! Since Complete Statement functionality is rather new, there may be bugs (stable version is planned for AppCode 2016.2). Also, for now it’s available only for Objective-C and C++, because for Swift we need to finish more important tasks related to completion which are currently in active development.

Anyway, feel free to share invalid cases with us so that we can fix them before the release. Thanks!

Your AppCode Team
JetBrains
The Drive to Develop

Comments below can no longer be edited.

4 Responses to Complete Statement in AppCode

  1. Bill A says:

    June 3, 2016

    So is this only for Objective-C? Does it work in Swift?

    • Stanislav Dombrovsky says:

      June 3, 2016

      Yes, it’s only for Objective-C/C++. In fact this change as well as some other was implemented by the CLion team for both languages as the part of their work on the C++ support. For Swift we first need to deliver parameter placeholders in completion, so any other completion feature will be considered after it. If you have any interesting use-cases for Complete Statement in Swift, all of them are very welcome as sub-tickets here

  2. Zmicier Zaleznicenka says:

    June 8, 2016

    Now I’m confused. Statement completion was available long before 2016.2. Maybe it was somewhat rudimentary (I never really liked the way it worked, if comparing with other IDEs) but it was there.

    • Stanislav Dombrovsky says:

      June 8, 2016

      Historically there were a lot of issues since this feature was enabled in AppCode, even in basic cases. Ok, may be “new feature” is not completely correct statement if we are talking about presence of the shortcut and action in the menu. If we are talking about using it on the daily basis – it’s correct statement in my understanding.

Subscribe

Subscribe to product updates