ios Xcode 只能重构 C 和 Objective-C 代码。如何在 Xcode 6 中重命名 swift 类名?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24133664/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Xcode can only refactor C and Objective-C code. How to rename swift class name in Xcode 6?
提问by Khawar
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 版本中创建了一个新的单一视图应用程序项目。我想将 swift class from 重命名ViewController.swift
为其他名称。但是当我选择 Refactor -> Rename 时,它给出了 error Xcode can only refactor C and Objective-C code
。
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 年时间才添加了这个基本功能。重构
回答by Newone
You can change name of a class in File Inspector at the right side of Xcode6.
您可以在 Xcode6 右侧的 File Inspector 中更改类的名称。
- 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.
就这样!以前我手动重命名类文件中的类名。
回答by Pescolly
I've been using Find>Find & Replace in Project, it's not perfect but it works.
我一直在 Project 中使用Find>Find & Replace,它并不完美,但它有效。
回答by Alessandro Pirovano
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
- 您可以将光标定位在要重命名的变量上
- 选择编辑器 - 在范围内编辑所有内容 (^?E)
- 重命名变量并自动编辑所有变量出现
回答by iPatel
Split up your iOS8 Swift Code
拆分你的 iOS8 Swift 代码
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.
首先,让我们将视图控制器重命名为更有意义的名称。打开您的 ViewController.swift 文件并将所有对“ViewController”的引用替换为我们的新名称“SearchResultsViewController”。将该文件也重命名为 SearchResultsViewController.swift。
如果您尝试从此处运行该应用程序,则会发生崩溃。这是因为我们的故事板文件尚未更新以了解新课程!因此,打开 Main.storyboard,选择场景中的“View Controller”对象(左侧导航),然后选择 Identity Inspector(右侧,第三个按钮)。
从这里让我们将类从“ViewController”更改为“SearchResultsViewController”。现在我们应该回到正轨了。检查项目是否仍然有效,让我们继续。
回答by vy32
Unfortunately, Apple hasn't gotten around to implementing it yet.
不幸的是,Apple 还没有开始实施它。
See http://www.quora.com/Why-isnt-there-a-refactoring-feature-for-Swift-language-in-Xcode-6for more information.
有关更多信息,请参阅http://www.quora.com/Why-isnt-there-a-refactoring-feature-for-Swift-language-in-Xcode-6。