Why standardize code?

1. Make yourself look professional (very important).

2. Your code is consistent with industry norms and easier to understand.

3. If you are the project leader, implementing code standardization will make the team work more efficiently.

On the other hand, when you read someone else’s shared code and find that it has strong personal characteristics that deviate from industry-accepted code norms, you are likely to want to give up because it has given you the impression of being unprofessional.

My experience

I have more than 5 years of experience in iOS development. I have experienced and led several teams, and I have some feelings:

1. The percentage of iOS developers who care about code specifications is small;

2. Changing habits is hard: Even when the team emphasizes the code specification, many people will ignore the details and continue their old habits.

3. The team leader’s sense of code specification determines the quality of the team’s code output.

I believe that many people often encounter others in the work of “messy” code, feel distressed, obsessive-compulsive disorder patients can not help but want to “add space”, “add line breaks”. Developers who have strict requirements for code specifications will also face the trouble of constantly adjusting code formats, which will affect coding efficiency.

The good news is that there are tools we can use to improve, to ensure code compliance while improving coding efficiency.

I’ve been working with formatting plugins on Xcode for a few years, from apple’s initial unrestricted use of plugins to the complete blocking of plugins starting with Xcode 8, and I haven’t given up because using some plugins makes development much more efficient.

Unsign Xcode is required to install plug-ins after Xcode8, but only the xcode after this unsigned can be used for development work, not for packaging, because it is not safe, Apple will not approve it, so you need to switch back to the previous Xcode when packaging. IOS Xcode8 插件 logo 图 片

There are many optional plug-ins, some of which are widely used, but there is a problem: each plug-in is only used by the Xcode with a specific UUID. If the UUID of Xcode changes after the upgrade, the plug-in becomes invalid. In this case, you need to go to the plug-in installation directory and replace the Xcode UUID value referenced by all plug-ins with the UUID value after the upgrade of Xcode. Reference: Xcode installed plug-ins can not be used

Apple has banned plug-ins, but has released an Extension: “Xcode Source Editor Extension.” Some plug-ins also support extensions. Using extensions, you do not need to unsign xcode or register a new UUID in the plug-in installation directory after upgrading Xcode.

There are a lot of handy and efficient tools at our disposal, but I’ve learned from my years of development that: 1) Developers tend to get too wrapped up in code to do anything else; 2. Even if you integrate efficient development tools, you may be interrupted by plug-in failure due to Xcode upgrade.

He that will do his work well must first sharpen his tools. Sometimes it’s our “lack of trying” that limits our vision. Take a little step and you may find something better.

.

The recommendation here is XCFormat, the code formatting tool used on Xcode. A personal memo, also hope to help you. Xcode version: 11.1.

1. Install XCFormat

Open Xcode and find Xcode Extensions in the menu bar…

On the page that opens, “Make programming faster with Xcode Extensions,” locate the XCFormat and click Install. (XCFormat is most likely at the bottom, with premium extensions at the top).

2. On the PC, choose System Settings > Extensions to enable XCFormat

3. Format code in XCFormat

Format the code from the menu Xcode->Editor->XCFormat.

4. Set shortcut keys for the formatting menu

For further efficiency, you can also add shortcuts. Remember the names of the two menus under “Xcode->Editor->XCFormat”, then go to the computer “System Settings -> Keyboard -> Shortcuts -> Apply Shortcuts”, enter the menu name, add shortcut keys.

Recommended reading

  • Clear the Mac disk space occupied by Xcode
  • How to debug and upgrade a new version of iPhone on a real phone without upgrading Xcode

 


I’m glad you finished reading this.

I am xi Yue, a program yuan.

At the age of 30, 2020 is a year of groping for progress, and we have set the flag of sharing articles with the stars.

If you are interested, please come to visit us often. We may have some sympathy as we grow up.

Our blog: Xiyuechen.net wechat official account “Stars and Evening moon”.