Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 276
Khawar Avatar asked Jun 10 '14 05:06

Khawar


People also ask

How do I rename a class in Xcode?

Luckily Xcode can take care of all the above for you. The trick is to open the interface file of the class to be renamed, select the class name in the @interface declaration and then from the Xcode Edit menu select Refactor -> Rename… Xcode then shows a dialog box prompting you for the new name of the class.

How do I refactor names in Xcode?

Xcode creates a new function, and highlights its name so you can rename it. If the lines of code reference parameters, Xcode includes those in the parameter list for the new function. To rename a parameter, Command-click it and choose Edit All in Scope, or Control-click it and choose Refactor > Rename.

Can you call Swift from Objective-C?

The Swift library cannot be directly called from Objective-C, since it is missing the required annotations in the code, and in many cases, modules do not inherit from NSObject, rather they use the native Swift data types.

Can we use Swift class in Objective-C?

You can work with types declared in Swift from within the Objective-C code in your project by importing an Xcode-generated header file. This file is an Objective-C header that declares the Swift interfaces in your target, and you can think of it as an umbrella header for your Swift code.


2 Answers

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.

like image 173
Newone Avatar answered Sep 24 '22 03:09

Newone


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

like image 43
Pescolly Avatar answered Sep 22 '22 03:09

Pescolly