Xcode只能重构C和Objective-C代码。如何在Xcode 6中重命名swift类名?

时间:2022-09-07 08:26:20

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.

我在Xcode 6 beta版中创建了一个新的单视图应用程序项目。我想从ViewController中重命名swift类。斯威夫特的另一个名字。但是当我选择Refactor ->重命名时,它给出的错误Xcode只能重构C和Objective-C代码。

Xcode只能重构C和Objective-C代码。如何在Xcode 6中重命名swift类名?

Any idea how to rename swift class in Xcode 6?

您知道如何在Xcode 6中重命名swift类吗?

UPDATE:

更新:

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

最后,Xcode 9支持对Swift的重构。苹果花了3年时间才添加了这一基本功能。重构

6 个解决方案

#1


25  

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

您可以在Xcode6右侧的文件检查器中更改类的名称。

  • open your class
  • 打开你的类
  • go to File Inspector > Identify and type section
  • 转到文件检查器>识别和类型部分。
  • rename existing class in "name" field.
  • 将现有类重命名为“name”字段。

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

这是所有!以前,我在类文件中手动重命名类名。

#2


15  

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

我一直在使用Find>查找和替换项目,它并不完美,但是很有效。

#3


12  

I use this way:

我用这个方法:

  • You can positioning the cursor on the variable that you want rename
  • 您可以将光标定位在您想要重命名的变量上。
  • Select Editor - Edit all in Scope (^⌘E)
  • 选择编辑-编辑所有范围(^⌘E)
  • Rename the variable and automatically all variable occurrences is edit
  • 重命名变量,并自动对所有变量进行编辑。

#4


10  

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.

首先,让我们将视图控制器重命名为更有意义的东西。打开你的ViewController。swift文件,并将所有对“ViewController”的引用替换为我们的新名称“SearchResultsViewController”。将文件重命名为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.

从这里我们将类从“ViewController”改为“SearchResultsViewController”。现在我们应该回到正轨上来。检查项目是否仍然有效,让我们继续。

#5


2  

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.

有关更多信息,请参见http://www.quora.com/why -isnt-there- refactoring-feat- for- quick -language-in- xcode -6。

#6


2  

Xcode 9

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

Xcode 9现在支持快速重命名。这是在2017年的WWDC上宣布的。

Xcode只能重构C和Objective-C代码。如何在Xcode 6中重命名swift类名?

#1


25  

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

您可以在Xcode6右侧的文件检查器中更改类的名称。

  • open your class
  • 打开你的类
  • go to File Inspector > Identify and type section
  • 转到文件检查器>识别和类型部分。
  • rename existing class in "name" field.
  • 将现有类重命名为“name”字段。

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

这是所有!以前,我在类文件中手动重命名类名。

#2


15  

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

我一直在使用Find>查找和替换项目,它并不完美,但是很有效。

#3


12  

I use this way:

我用这个方法:

  • You can positioning the cursor on the variable that you want rename
  • 您可以将光标定位在您想要重命名的变量上。
  • Select Editor - Edit all in Scope (^⌘E)
  • 选择编辑-编辑所有范围(^⌘E)
  • Rename the variable and automatically all variable occurrences is edit
  • 重命名变量,并自动对所有变量进行编辑。

#4


10  

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.

首先,让我们将视图控制器重命名为更有意义的东西。打开你的ViewController。swift文件,并将所有对“ViewController”的引用替换为我们的新名称“SearchResultsViewController”。将文件重命名为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.

从这里我们将类从“ViewController”改为“SearchResultsViewController”。现在我们应该回到正轨上来。检查项目是否仍然有效,让我们继续。

#5


2  

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.

有关更多信息,请参见http://www.quora.com/why -isnt-there- refactoring-feat- for- quick -language-in- xcode -6。

#6


2  

Xcode 9

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

Xcode 9现在支持快速重命名。这是在2017年的WWDC上宣布的。

Xcode只能重构C和Objective-C代码。如何在Xcode 6中重命名swift类名?