It is recommended to read the code in landscape

interface

Xcode 13 has redesigned the Project Navigator, using symbolic ICONS for various file types. By default, file extensions are hidden. Overall, the look and feel is cleaner.

Xcode Cloud

Xcode Cloud is an important complementary feature for team collaboration. It allows continuous integration and delivery, parallel testing across multiple device types, and automatically pushes apps to TestFlight, making it easier for testers to get the latest version of a project build.

Source editor

The source code editor is where we spend the most time in the development process, and Xcode 13 has improved a number of details in the source code editor, especially the auto-complete feature.

Automatic import

If you write code using a type that is not currently available, Xcode will automatically import the relevant framework for you. For example, if you write code like this:

struct ExampleView: View
Copy the code

Xcode will detect that the View belongs to the SwiftUI framework and automatically add import SwiftUI to the source header during code completion.

Unpack statements are automatically completed

If you try to unpack a selectotype, Xcode will now complete it for you. Try the following code:

struct UserGreeting {
    func greet(name: String?). {
        if let na
    }
}
Copy the code

When you type if let na, Xcode will provide if let name = name as an autocomplete option.

Autocompletion of deeper paths

Xcode can now also provide deep path autocompletion for properties under properties. Try the following code:

class ExampleVC: UIViewController {
    override func viewDidLoad(a) {
        let someText = UILabel()
        view.corn
        view.addSubview(someText)
    }
}
Copy the code

When you type view.corn, Xcode will provide view.layer.cornerRadius as the completion option – it actually checks the properties under the layer and promotes them to the upper layer as the completion option.

Switch Case Automatic completion

Xcode now automatically completes all enumerated cases when you use a switch statement. Try the following code:

struct PaintMixer {
    enum Color {
        case red, green, blue, tartan
    }

    func handle(color: Color) {
        switch col
    }
}
Copy the code

When you type switch COL, Xcode automatically completes col to color and populates all possible cases of the enum type.

Automatic completion of array traversal statements

When you walk through an array, Xcode can now automatically complete the for statement for you using the singular form of the array name. Try the following code:

struct NamePrinter {
    let names = ["Becca"."Holly"."Ted"]

    func printNames(a) {
        for nam
    }
}
Copy the code

When you type in for nam, Xcode automatically completes the rest, printing for name in names — it knows that names are plural, and creates a singular version to use as the variable name to iterate over.

If I had to guess, I’d guess that this feature is based on some kind of machine learning strategy, since Xcode understands complex numbers in all their forms — including irregular complex numbers. Try the following code:

let indices = [1.2.3]
let people = ["Eric"."Maeve"."Otis"]
let millennia = [1000.2000.3000]
let geese = ["Golden"."Mother"."Untitled"]
Copy the code

Column a breakpoint

Xcode 13 lets you place “column breakpoints” — breakpoints that can be inserted exactly in the middle of a line of code, rather than just the whole line of code that used to be available.

For example, we might call multiple functions like this to produce a single value:

func first(a) -> String { "A" }
func second(a) -> String { "B" }
func third(a) -> String { "C" }

func buildString(a) -> String {
    first() + second() + third()
}
Copy the code

If we put a breakpoint on the buildString() line, we need to Step Into each function separately to see the code. But if we have a rough idea of what the problem is, we can simply place a “column breakpoint” — for example, by having Xcode stop exactly at the call point to second().

You can try the Code above by selecting second() and then pressing Shift+Cmd+A to bring up the Code Actions — or right-click on the menu and select Show Code Actions. You’ll see Set Column Breakpoint.

Column breakpoints work the same way as regular row breakpoints. So you can click and drag them, or right-click and edit them to add custom Settings.

Vim model

The last improvement to the Xcode source editor deserves special attention because it is a feature that some programmers may love.

This feature is called Vim Key Bindings and you can Enable itin Xcode’s preferences — go to Text Editing and check Enable Vim Key Bindings.

If you haven’t used Vim before, here’s a quick introduction. Vim is a command-line text editor that became popular as a predecessor to Vi in 1976 and was upgraded to “Vi Improved” (Vim for short) in 1991. Vim works in a very special way that requires careful understanding of the keyboard (in the sense that Vim is highly dependent on the keyboard, which is the key to efficient coding). Now, you can finally apply most of the operations you use in Vim in Xcode 13.

I say “mostly” because Xcode 13 currently only supports a subset of Vim shortcut bindings: navigation, insert, yank, search, etc., but relative line numbers, repeat actions, and save :w are not supported. Still, it’s a good start, and I’m sure more practical actions will follow.

Version control improvements

Xcode has been integrating version control for quite some time, but this year it got its biggest upgrade ever — it’s easier to compare changes between any two releases, and you can open pull requests in Xcode to invite code reviewers, Even handle Code Review directly within the IDE.

** Tip: ** You need to turn on Xcode’s source control for this to work. If you have disabled this feature, go to Preferences > Source Control and check Enable Source Contro to Enable it again.

Create custom documents with DocC

Xcode 13 now has the ability to create document sets directly from code. It reads your Markdown comments and builds them into Xcode’s help system, using the same layout and format as Apple’s own framework.

Readers interested in DocC are advised to read the official account’s previous tweet, “Exploring DocC.”


For more articles, please follow the wechat official account: Swift Garden