From the course: Xcode 15 Essential Training

Unlock this course with a free trial

Join today to access over 24,000 courses taught by industry experts.

Refactoring code

Refactoring code

- [Instructor] Another way in which Xcode helps you to be efficient in writing your code is by allowing you to refactor using a small number of clicks. For example, let's say we wanted to change the name of this method, getText. This feature works the same whether your method is used in one file or in multiple files. To change the method name, select the method either here on line 21 where it's defined, or on line 16 where I'm calling it, and then go into the editor menu. Choose Refactor, and then Rename. Or you can right-click the method and then do the same thing, Refactor, Rename. In here, you're asked to give the method a new name. Let's call it getTheText, and then I'm going to press return on my keyboard to commit the change. And you'll notice it's instantly updated in the editor. So if you want to do refactoring in your code, whether it be renaming or one of the other available options, simply right-click the affected code or go to the editor menu, choose Refactor, and then…

Contents