I am trying to rename the class name in swift but it gives me error Can\'t refector swift code
. I want to know the best way to rename a file that will reflect in t
Now it's possible in Xcode 9.
Right click on class name and choose Rename.
Currently you can't refactor in Swift. However, you can do Find menu > Find and Replace in Project. (Carefully)
Edit: Xcode 9 allows you to refactor.
Highlight your property/function and choose Editor Menu -> Refactor -> Rename
Wait a second or two for Xcode 9 to scan your project for all occurrences and then type the new name.
EDIT:
Starting Xcode 9 you're now to easily do it.
Highlight the code that you want to rename, right click and choose refactor
-> rename
.
Or you can also use the Editor
menu on top of the Xcode and choose refactor
-> rename
.
Solution Below XCode 9:
Find
-> Find and Replace in Workspace
ChatViewController
with ChatVC
then hit Enter
. This usually rename the naming in storyboard too, So it's really convinient, but just double check if you want to really make sure it's changed. After doing what @Caroline has pointed out, you should also change the name of your .swift
file because it does not change using Find > Find and replace...
. For doing that, you can click on the name of a .swift
class and rename it as you want.
I am using XCode 8
and it is the best option I could find to change the name of my class in the whole project.
AppCode by Jetbrains can refactor/rename both Swift and Objective-C classes quite easily; It's not free but it does a great job.
cmd + shift + F
Show the identify inspector
to new class name.TIP Set scope under the search field for Find & Replace
can make this work clear.