Good articles to my personal technology blog: https://cainluo.github.io/15096944292979.html


With the release of iOS 11, Xcode 9 has been released. This time, Xcode 9 has a whole bunch of updates, which is great news for Swfit writers, because in Xcode 9, support for Swift refactoring has been added. Since Xcode 9’s code editor was rewritten in Swift, it is much more user-friendly in supporting Swift, such as scrolling, searching, refactoring, and so on.

In addition, Xcode 9 also includes support for MarkDown files, which means you can edit MarkDown files on Xcode 9, the ability to connect wirelessly to devices for the first time, and the ability to have multiple emulators open at the same time while using emulator Debug.

Having said so much, I’m sure my mouth is watering, so let’s get down to business.

This time we’re going to write a little something that’s new in Xcode 9 using Objective-C and Swift.

Reprint statement: if you need to reprint this article, please contact the author, and indicate the source, and can not modify this article without authorization.


Swift shortcut

We can hold down the Command key to move the mouse over the func and var keywords, and notice some different changes. In func, the mouse is clickable, while in let and var the mouse is unresponsive:

Move to Double and find that you can also click on it. Click to access some of the methods and properties inside:

We can also press Command to move the if-else keyword to if, so that we can see the whole if-else structure:

In addition to seeing the entire structure of if with Command, we can also call out a small menu using Control+Command:

There is also a change in the way Xcode 9 calls are made using the Command click method, which by default pops up a small box instead of jumping directly inside the function:

4. If we need to change it, we can set the “Jumps to Definition” in Xcode’s Navigation TAB:

Instead of setting this, we can also click on the function name and use Command + Control + J to jump to it.


Refactoring is fat again

Previously, Swift refactoring was not supported in Xcode 8. In Xcode 9, this feature is back and much easier to use, and supports Objective-C and Swift:

When you’re Done, press Enter to confirm or click Done in the upper right corner.

One problem is that Xcode 9 often gives me errors when I use Refactor. I wonder if you have encountered this problem.


completion

Sometimes when we declare a structure with Swift we usually declare some protocol, but sometimes things happen when we declare, like forgetting to write protocol methods, but in Xcode 9 we don’t have that problem.

When we forget to write an agreement, Xcode 9 will prompt us, and we can click the corresponding prompt to complete it:

The code after completion:

struct Person {
    
    let name: String
    let height: Double
    
    init(name: String, height: Double) {
        
        self.name = name
        self.height = height
    }
}

extension Person: Equatable {
    static func= =(lhs: Person, rhs: Person) -> Bool {
        return lhs.name == rhs.name
    }
}
Copy the code

Of course, in addition to this, there is the Switch case, there is also the completion “”, [] these have.

In addition, when we encounter some complicated judgment conditions, in order to better see the logic, we can use this completion method:

    let latitudeString = latitudeTextField.text == "1" ? "100" : "23"
Copy the code

LatitudeTextField. Text == “1” and shift + (,

    let latitudeString = (latitudeTextField.text == "1")?"100" : "23"
Copy the code

The font scaling

Before, if we want to adjust the Font size, we need to go to the Settings of Xcode, and then we can adjust the Font, but in Xcode 9, we don’t need to change the Font size.

We can use Command + + or Command + – to reduce and enlarge the font size of our code.


Code zoom

In previous Xocde, we could shrink the code block by edge, but now in Xcode 9, this operation has been removed (at least I did not find, if any friends find where to call, please let me know ~).

In Xcode 9, whenever it’s inside a function, or a structure, or whatever, it’s inside a {}, you can scale with Command + option + left key, or if you want to release it, Command + option + right key.


The line spacing between codes

If you use Xcode 9, you will notice that the space between the lines of code is much wider. In Xcode 9, there are three ways to space the lines:

  • Tight Spacing
  • Normal Spacing
  • Relaxed Spacing

There are also three types of cursor styles, which can be seen in Xcode Settings:


The project address

The address of the project: https://github.com/CainRun/iOS-11-Characteristic/tree/master/1.Xcode%209


The last