Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

variable name changing in whole program

Tags:

xcode

ios

Is there a provision in Xcode, that I can specify which variable name I want to change, and wherever that variable is used in all of the program, the old name is replaced by the new one, without affecting the program in any way. Is there a way to do it ? thanks

like image 227
Farhan Misarwala Avatar asked Dec 02 '22 16:12

Farhan Misarwala


1 Answers

Sometimes "edit all in scope" is useful when you want to replace a variable or method name within a single source file. Select the variable or method name in question and then press command+control+e and as you edit it, it will simultaneously change it everywhere appropriate for the scope of that symbol (which, for class property, ivar, or method, will be everywhere in that class).

If you need something broader than a single source file, then you may want to use “Editor” » “Refactor” » “Rename” and it will find all occurrences in multiple source files throughout the project, including, storyboards, NIBs, etc. If files need to be renamed, as part of the process (e.g. you’re renaming some class/struct that was defined in a source file of the same name). It can even find occurrences of the renamed type in comments and string literals (though by default, those won’t be changed unless you explicitly tap the + icon next to that occurrence):

enter image description here

The “Refactor” » “Rename” is not perfect, but it dramatically simplifies renaming of types, enumerations, properties, etc., throughout a project. It’s especially useful when renaming an @IBOutlet and @IBAction references, updating the storyboard references, too, saving you from having to go back, remove old storyboard references and hooking up the renamed ones.

like image 143
Rob Avatar answered Dec 07 '22 01:12

Rob