Xcode can only refactor C and Objective-C code. How to rename swift class name in Xcode 6?

IosSwiftXcodeXcode6Xcode9

Ios Problem Overview


I have created a new Single View Application Project in Xcode 6 beta version. I want to rename swift class from ViewController.swift to some other name. But when I select Refactor -> Rename, it gives error Xcode can only refactor C and Objective-C code.

enter image description here

Any idea how to rename swift class in Xcode 6?

UPDATE:

Finally Xcode 9 is supporting Refactoring for Swift. It took Apple 3 years to add this basic feature. Refactoring

Ios Solutions


Solution 1 - Ios

You can change name of a class in File Inspector at the right side of Xcode6.

  • open your class
  • go to File Inspector > Identify and type section
  • rename existing class in "name" field.

That's all! Previously I manually rename the class name in the class file.

Solution 2 - Ios

I've been using Find>Find & Replace in Project, it's not perfect but it works.

Solution 3 - Ios

I use this way:

  • You can positioning the cursor on the variable that you want rename
  • Select Editor - Edit all in Scope (^⌘E)
  • Rename the variable and automatically all variable occurrences is edit

Solution 4 - Ios

From this tutorial.

Split up your iOS8 Swift Code

>First things first, let’s rename our View Controller to be something more meaningful. Open up your ViewController.swift file and replace all references to ‘ViewController’ with our new name, ‘SearchResultsViewController’. Rename the file as well to SearchResultsViewController.swift. > >If you try to run the app from here you’ll get a crash. This is because our storyboard file hasn’t been updated to know about the new class! So open up the Main.storyboard, select your ‘View Controller’ object in the scene (the left-hand side nav), and then select the Identity Inspector (right-hand side, third button.) > >From here let’s change the class from ‘ViewController’ to ‘SearchResultsViewController’. Now we should be back on track. Check that the project still works, and let’s proceed.

Solution 5 - Ios

Xcode 9

Xcode 9 now supports renaming in Swift. This was announced in WWDC 2017.

enter image description here

Solution 6 - Ios

Unfortunately, Apple hasn't gotten around to implementing it yet.

See http://www.quora.com/Why-isnt-there-a-refactoring-feature-for-Swift-language-in-Xcode-6 for more information.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionKhawarView Question on Stackoverflow
Solution 1 - IosNewoneView Answer on Stackoverflow
Solution 2 - IosPescollyView Answer on Stackoverflow
Solution 3 - IosAlessandro PirovanoView Answer on Stackoverflow
Solution 4 - IosiPatelView Answer on Stackoverflow
Solution 5 - IosGuy DaherView Answer on Stackoverflow
Solution 6 - Iosvy32View Answer on Stackoverflow