Complete Statement in AppCode
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:
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
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:
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:
Complete Statement can also be used with other control statements, such as
Invoke Smart Completion to allocate the cell and specify the cell type after it:
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:
Move the caret to the
initWithStyle method, jump to the second parameter using
Tab, invoke Basic Completion and finish it with Complete Statement again:
Now we can return the cell from the method – invoke Basic Completion and finish it with
Tab instead of
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
The Drive to Develop
AppCode 2023.1 Bug-Fix Update
Hi, AppCode 2023.1 has just been released with fixes for Xcode 14.3 compatibility, Swift refactorings and intentions, the IDE’s UI, and Kotlin Multiplatform Mobile. On December 14, 2022, along with the AppCode 2022.3 release, we sunsetted the product and stopped sales. While we’ve refocused the te…
AppCode 2023.1 Release Candidate
Hi, On December 14, 2022, along with the AppCode 2022.3 release, we sunsetted the product and stopped sales. While we’ve re-focused the team's efforts in other directions, we’ve kept providing technical support to our current users and are releasing bug-fix updates in 2023, targeting mostly the Xco…
AppCode 2022.3 Release and End of Sales and Support
AppCode 2022.3 has just been released. With the release of v2022.3, we are sunsetting the product.
AppCode 2022.3 Release Candidate Is Here
Hi everyone, The release of AppCode 2022.3 is approaching, and the release candidate (build 223.7571.233) is now available for download on our website. You need to have an active subscription or activate a free trial to use this build. The main highlights of this build include: We fixed the r…