Go Xcode Refactoring Features

Source: Internet
Author: User

Xcode provides several refactoring features:

    • Rename

    • Extract

    • Create Superclass

    • Move up

    • Move down

    • Encapsulate

The location in the menu bar is as follows:

The context menu for refactoring can also appear in the code area directly right-click:


The use of these refactoring features is described below.

Rename: Renaming

You can try almost any symbol: class name, method name, function name, property name, and so on. It is very simple to use, select a symbol to be named, choose Rename, will pop up an input box to let you enter the new name you want, after the completion of the input, click Preview can be previewed.

Preview after modifying a property name

Extract: Extracting code as a separate method or function

After you select a piece of code (which can include comments), select Extract to automatically generate a method signature after analyzing the code snippet you selected. You can modify the method name, and you can modify it yourself if the parameter or return value is incorrect.

If function is selected, it is a different format:

If you find some adjustments in the preview, you can edit them directly in the preview box.
Here's a preview of how to extract a Doublevalue method:

Create superclass: Creating a parent class

This is a good idea to create a parent class of the current class. It is important to note that the class name is selected to trigger successfully.
It is important to note that the left-most navigation area of the preview interface is selected in the middle, and this refactoring will affect the file list. You can view changes to other classes by clicking to this tab.


If there is a warning, the tab for the warning is displayed by default.

Move Up & Move Down

Move up: You can move a method, instance variable to the parent class. When triggered and renamed, the instance name or method name is selected for normal use. Not applicable in category.

Move Down: Instead, the selected instance variable is moved to a subclass. Yes, the method cannot be moved to the child class. It is logically difficult to understand why this is so. But Apple's father is so willful.

Encapsulate: Package

This is a nostalgic word, after many years to see or will think of the final exam in the three main characteristics of the fill-in question.
The purpose of this is to automatically generate a get and set method for you after you select a variable.
Here's a preview of the VARIABLESTR variables I've encapsulated:

Some novices may not understand this feature very well. Because the GET, set method is automatically generated when the property is declared. So this feature should be a bit out of date.
If you have used Eclipse's classmates may want to hehe, this we understand.

Something sad.

These refactoring features do not have shortcut keys.
Although it seems that I can not remember Ah!
Don't do that, White want who don't.
So if I just pretend to be forced shortcut key party, do not want to let others know I chose this function how to do?
Perhaps the world you can also forget, at least there is a key binding worthy of you to cherish:

Refactor-keybindings.png

Something more sad.

Hate me. When you use Swift, the following prompt box appears after you select a extract.

My heart:

Go Xcode Refactoring Features

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.