Auto-Completion Feature Improvements in Xcode 14

Photo of Sebastian Wojciechowski

Sebastian Wojciechowski

Updated Dec 4, 2023 • 6 min read
auto-completion feature Xcode 14

Apple describes Xcode version 14 as "everything you need" to build software for their platforms. The company implemented a number of improvements, such as several updated auto-completion functions, to increase Xcode’s performance. Read on to find out which ones I have found particularly important and see how they work in practice.

Xcode is Apple’s Integrated Development Environment (IDE), a tool used to develop the Apple brand’s apps. Xcode 14 was announced at the Worldwide Developers Conference 2022 in June and was released in September. Since then, I have had some time to explore it and would like to share my insights on the auto-completion feature, which is greatly improved now.

Auto-Completion feature novelties

Struct initializer

Let’s take the following scenario: you implement a struct for your app and declare its members. However, you then want to modify some parts. In the past, Xcode wasn’t able to adjust to the changes without your interference. If you wanted to, for instance, add some logic tests or combine values, you had to create the init, fill it, and then modify it manually. This is no longer the case: IDE’s 14 version fills the init for you.

Here’s an example of a simple Contact struct:

Codable conformance

Formerly, if devs wanted to add coding keys or init from the decode and encode method, we had to add boilerplate code ourselves. Now, it's done by Xcode – you can start typing coding keys, press enter, and the code fills up. This solution works similarly with inits from the decoder. When you have the memberwise inits or use the encoding method, auto-completion suggests suitable boilerplate code.

Take a look at the codable protocol in practice:

Parameters with a default value

So far, so good, right? The next improvement concerns the Contact struct: the parameters with default values will behave differently now. After you start typing, you might notice that parameter names are in different fonts and colors. Some names are in a lighter shade of gray, while others are italicized and darker. This visual distinction shows that the latter has a default value, so now if you press enter, it won’t be added to other parameters.

How do you implement this? The first method is holding down the option key and pressing enter. You can also do so by starting to type the parameter name. In the second method, you can already press enter when the beginning is marked – Xcode will add the just-typed parameters along with the rest of the required ones.

Let’s see these differences in parameters with a default value:

Map predictions

Xcode will now also help with extracting the values from more straightforward structs through suggestions. When you want to create a constant that includes all variables with a particular keyword, then suggestions are a great way to do so. This feature has its limitations though. In the case of variables that include the same keyword, Xcode takes the first member that matches the name, regardless of whether that was the exact member of your choice or not.

Just to give you an example. Let's say we want to get all first names creating firstNames type of contacts. Xcode will suggest map { $0.firstName }. You can see that Xcode sees the names keyword, then looks if we have an array with a member with a singular name in our case. Contact has firstName, lastName, and fullName, so it doesn't know which one to use. It takes the first member that matches the keyword.

This is how those suggestions work:

List and forEach

From my experience, the following case can be quite common: you have an array of entities and have to show some data in rows. Most likely, you would use List or ForEach to present it. In SwiftUI environments, you would have to write some letters of function and the name of the variable. With the latest Xcode update, that’s not the case anymore: Apple’s IDE now autocompletes the code for you.

Take a look at how this has been automated below:

Frame prediction

When creating views in SwiftUI, you often customize their size with a function written alongside the variable. To change a variable's size, you had to type the entire function, for example, .frame(width: 1) to see the result. In Xcode, you can simply type .width or any other parameters of the frame functions to see the result.

Here are the frame predictions in action:

Auto-alignment

The days of pressing Ctrl and L to align the code are now gone! Finally, wrapping blocks of code automatically reindent.

Below you can see an example of this new feature:

No Argument Label

Sometimes you want to rename a function with another one that uses the same arguments. It can often be inconvenient as all parameters remain with the function and you have to delete them manually. Xcode no longer autocompletes already written argument labels.

Check out how labeling works after the update:

Xcode 14 as an efficiency boost for writing code

Xcode has been continuously revised and improved since its launch in 2003. Devs can now benefit from improved struct initializers and auto-alignment that minimize manual jobs. Other updated functions, such as parameters with default values or frame predictions, maximize the IDE’s performance. In Xcode 14, completions, including codable conformance and map predictions, come up quicker and are more predictive, thereby increasing tool reliability. All these functions of the auto-completion feature help developers write code more efficiently and further excel in working with software for the Apple platforms.

Photo of Sebastian Wojciechowski

More posts by this author

Sebastian Wojciechowski

iOS Developer
Create impactful mobile apps  Expand reach and boost loyalty. Get started!

Read more on our Blog

Check out the knowledge base collected and distilled by experienced professionals.

We're Netguru

At Netguru we specialize in designing, building, shipping and scaling beautiful, usable products with blazing-fast efficiency.

Let's talk business