Auto-Complete Improvements in Xcode 14

Apple describes Xcode 14 as “everything you need” to build software for its platforms. The company has implemented a number of improvements, such as several updated auto-completion features, to improve Xcode’s performance. Read on to find out which ones I find particularly important and see how they work in practice.

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

What’s New in AutoComplete

Initializer in Struct

Let’s consider the following scenario: you implement a struct for your application and declare its members. However, then you want to change some fragments. In the past, Xcode could not adapt to changes without your intervention. For example, if you wanted to add some logic tests or concatenate values, you had to create an init, populate it, and then modify it manually. Now that’s not the case: the 14th version of the IDE fills init for you.

Here is an example of a simple Contact structure:

Compliance Codable

Previously, if developers wanted to add coding keys or init from the decode and encode method, we had to add boilerplate code ourselves. Now Xcode does it – you can start typing coding keys, press enter, and the code will fill in. This solution works similarly with initialization from the decoder. When you have element-wise initialization or you use an encode method, autocomplete suggests the appropriate 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 structure: now parameters with default values ​​will behave differently. After you start typing, you may notice that the parameter names appear in a different font and color. Some names are in a lighter shade of gray, while others are italicized and darker. This visual difference shows that the latter has a default value, so now if you hit enter it won’t be added to the other options.

How do you implement it? The first way is to hold down the option key and press Enter. You can also do this by starting to type the parameter name. In the second way, you can press Enter already when the start is marked – Xcode will add the parameters you just typed along with the rest of the necessary ones.

Let’s take a look at the following differences in parameters with a default value:

Map offers

Now Xcode will also help extract values ​​from simpler structures using suggestions. When you want to create a constant that includes all variables with a particular keyword, clauses are a great way to do it. However, this feature has its limitations. For variables that include the same keyword, Xcode takes the first element that matches the name, whether or not it was the element you selected.

Just for example. Let’s say we want to get all the names by creating a firstNames type for contacts. Xcode will suggest map {$0.firstName}. You can observe that Xcode sees the names keyword and then looks to see if we have an array with an element with a single name in our case. The contact consists of firstName, lastName and fullName, so it doesn’t know which one to use. It takes the first element that matches the keyword.

Here’s how these suggestions work:

List and forEach

In my experience, the following situation can be quite common: you have an array of entities and need to show some data in rows. You would most likely use a List or ForEach to represent it. In SwiftUI environments, you would have to write several function letters and a variable name. With the latest Xcode update, this is no longer the case: Apple’s IDE now auto-completes code for you.

Take a look at how it’s been automated:

Frame offer

When creating views in SwiftUI, you often adjust their size with a function written next to the variable. To resize a variable you need
was to enter the whole function like .frame(width: 1) to see the result. In Xcode, you can simply type in .width or any other parameters of the frame functions to see the result.

Here are frame suggestions in action:

Auto alignment

Gone are the days of pressing Ctrl and L to align code! Finally, wrapped code blocks align automatically.

Below you can see an example of this new feature:

Label with no argument

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

See how label assignment works after the update:

Xcode 14 as an efficient coding accelerator

Xcode has been constantly updated and has been improving since its launch in 2003. Developers can now take advantage of improved structure initializers and auto-alignment that minimize manual work. Other updated features, such as options with default values ​​or frame clauses, maximize the performance of the IDE. In Xcode 14, completions, including codable matching and map clauses, are faster and more predictable, making the tool more robust. All these auto-completion features help developers write code more efficiently and succeed even more. in working with software for Apple platforms.

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *