![]() ![]() With the caret placed at the variable declaration, press ⌥⇧↑ to put this line before the body structure and press ⌥⌘L to fix the code formatting: The variable name suggested by default is conferences. Now you can choose if you want to declare the new variable with var and specify the variable type explicitly: The variable declaration will appear right above the List object. Select the expression in brackets and press ⏎: Alternatively, press ⌃T and then 5 to select the refactoring from the list. Place the caret at the loadFile() method call and press ⌥⌘V. This will make the code more clear and allow you to get rid of the type cast. You can extract the expression in brackets to a variable named conferencesData. This will bring you to the List object with the loadFile() method passed as its parameter. In the TODO tool window ( View | Tool Windows | TODO), double-click the Introduce Variable comment. The Introduce Variable refactoring may come in handy when you want to make your code more readable and clear, lighten up complex constructions, or avoid code repetition. To delete the whole line at once, place the caret at it and press ⌘⌫. To close the dialog, just click somewhere outside. You can do it directly in the preview of the Find in File dialog: Still, for the sake of consistency, rename it to ConferencesList_Preview. It was not renamed by the refactoring since it is a separate symbol. The only ContentView occurrence left is the ContentView_Previews class. Now you see the usages in comments will also be affected. Select the Search in comments and strings checkbox and enter the new name - ConferencesList:Ĭlick Preview to check all the occurrences that are going to be renamed: Place the caret at ContentView again and press ⇧F6 twice. Undo the refactoring by pressing ⌘Z and in the dialog that opens confirm this action. By default, text in comments is not changed when calling the Rename refactoring this way - you should perform it a little differently. The first occurrence appears in comments. There are two occurrences left, let’s take a closer look at them: Press ⇧⌘F and in the dialog that opens type ContentView and make the search for the case-sensitive by clicking. Nevertheless, let’s check if the structure name has been changed everywhere in the project. This action changes not only the structure name and its usages but also the name of the file. When the structure name gets highlighted, type the new name and press ⏎: Alternatively, select Refactor | Rename from the main menu. Place the caret at the structure name and press ⇧F6. Though the application consists of two views only, the name of this one definitely could be more precise. ContentView is a SwiftUI view that displays the list of conferences. In the TODO tool window, double-click the Rename comment to navigate to the ContentView structure. The Rename refactoring in AppCode allows you to safely change the name of a file, class, method, variable throughout the whole project. You may need it, for example, when you notice that a class, method, or variable name either does not follow the company’s guidelines, or its functionality was extended, and the name should be updated accordingly. ![]() Renaming is one of the simplest and most frequently used operations that can significantly improve readability of your code. Read more on how to work with TODO comments in AppCode in TODO comments help article. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |