Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to rename the class name in swift?

Tags:

ios

swift

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 the whole project

like image 874
Sunny Shah Avatar asked Dec 02 '14 04:12

Sunny Shah


People also ask

How do I rename a file in Xcode?

Right-click on the class name in the interface ( . h ) file, choose Refactor->Rename , and Xcode will guide you through the process, allowing you to preview changes before you commit to them. Xcode will let you review the changes before you commit.


2 Answers

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.

like image 180
Caroline Avatar answered Sep 21 '22 01:09

Caroline


Now it's possible in Xcode 9.

Right click on class name and choose Rename.

like image 35
Sunny Shah Avatar answered Sep 22 '22 01:09

Sunny Shah