Move refactoring moves routine away
AppCode offers a wide variety of code refactorings, which track down and correct the affected code references automatically. Some of them are widely known and often used, others are just missed. Move refactoring is present in AppCode since 2.1 version, but have you ever used it? Let’s take a closer look at it.
Generally speaking, there’s nothing special about Move refactoring, but in complex projects with a large code base, it really saves your time when, for example, you move a method to a new place that turns out to be a lot harder than you thought it would be. The Move refactoring allows you to move classes, protocols, methods, functions within a project – AppCode automatically corrects all references to the moved symbols in the source code.
To invoke the Move action, press
F6. Another way is to call Refactor This action with
⌃T and select Move there.
When moving class members AppCode lists all available members in a dialog form and highlights with red those that are used by the selected members (hover the mouse on any of these red members to find out which one exactly is using it):
AppCode also groups members and marks properties, instance variables, interface methods, etc. with an appropriate icons to help you navigate easier through the list.
You can move members to an existing class – start typing the name and AppCode will help you completing it. Another option is to search it by its name or just look through the whole project. In any case, for easier navigation over the items AppCode highlights matches for you – just type a couple of letters from the name you are looking for:
If the proper class doesn’t exist just type its name in the destination field and AppCode will create it for you.
You can now refactor immediately, or use the Preview button to see the changes that will be performed. All the usages of the moved element are grouped by type and location, plus you can easily exclude usages you don’t want to modify:
AppCode will search all references of these members and make sure they are updated. The IDE will notify you about potential problems as well and suggest to look through the conflicts in a separate window:
You can still refactor if you are sure or cancel it, if you agree with the usage conflicts.
Try the same workflow to also move functions, classes or protocols!
See more tips’n’tricks.
Subscribe to Blog updates
Writing Code Documentation in AppCode
Code documentation can save you a lot of time and headaches. On the other hand, it also takes a lot of effort to write and maintain it. In this article, we will look at the AppCode features that can help you create detailed and well-structured code documentation and keep it updated after code refact…
Polish Your Code with AppCode’s Inspections and Intentions
AppCode is constantly analyzing your code to find parts that can be improved. It provides sets of code inspections and intention actions for each supported language for this exact purpose. Inspections locate unused or redundant code, syntax errors, probable bugs, spelling mistakes, obsolete or redun…
Navigation in AppCode
Navigating through files and source code, especially in complex projects, can eat up a lot of time, which is why it is essential to learn how to move around quickly in your IDE. AppCode provides plenty of navigation features that can help you move faster. In this blog post, we’ll take a look at some…
Server-side Swift in AppCode
In this short article we’ll take a look at various AppCode features that are useful for server-side Swift development, as now you can open standalone SPM projects in AppCode on macOS. Check out and open the project On the Welcome screen, click the Get from VCS button and enter the address of the Fe…