ios 如何快速重命名类名?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/27241881/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 03:51:38  来源:igfitidea点击:

How to rename the class name in swift?

iosswift

提问by Sunny Shah

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

我试图在 swift 中重命名类名,但它给了我错误Can't refector swift code。我想知道重命名将反映在整个项目中的文件的最佳方法

采纳答案by Muhammad Fauzi Masykur

EDIT: Starting Xcode 9 you're now to easily do it. Highlight the code that you want to rename, right click and choose refactor-> rename. Or you can also use the Editormenu on top of the Xcode and choose refactor-> rename.

编辑:启动 Xcode 9,您现在可以轻松完成。突出显示要重命名的代码,右键单击并选择refactor-> rename。或者您也可以使用EditorXcode 顶部的菜单并选择refactor-> rename

Solution Below XCode 9:

XCode 9 下的解决方案

  1. click Find-> Find and Replace in Workspace
  1. 点击Find->Find and Replace in Workspace

enter image description here

在此处输入图片说明

  1. Rename it, for example I am renaming ChatViewControllerwith ChatVCthen hit Enter. This usually rename the naming in storyboard too, So it's really convinient, but just double check if you want to really make sure it's changed.
  1. 它重命名,例如我重新命名ChatViewControllerChatVC再命中Enter。这通常也会重命名故事板中的命名,所以它真的很方便,但只要仔细检查你是否真的想确保它已经改变。

enter image description here

在此处输入图片说明

  1. Lastly, Dont forget to rename the file itself in the project navigator
  1. 最后,不要忘记在项目导航器中重命名文件本身

enter image description here

在此处输入图片说明

回答by Caroline

Currently you can't refactor in Swift. However, you can do Find menu > Find and Replace in Project. (Carefully)

目前你不能在 Swift 中重构。但是,您可以在项目中执行“查找”菜单 >“查找和替换”。(小心)

Edit:Xcode 9 allows you to refactor.

编辑:Xcode 9 允许您重构。

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.

等待一两秒钟,让 Xcode 9 扫描您的项目以查找所有出现的项目,然后键入新名称。

回答by Sunny Shah

Now it's possible in Xcode 9.

现在可以在Xcode 9 中实现

Right click on class name and choose Rename.

右键单击类名并选择Rename

回答by Francisco Romero

After doing what @Caroline has pointed out, you should also change the name of your .swiftfile because it does not change using Find > Find and replace.... For doing that, you can click on the name of a .swiftclass and rename it as you want.

在完成@Caroline 指出的事情后,您还应该更改.swift文件的名称,因为它不会使用Find > Find and replace.... 为此,您可以单击.swift类的名称并根据需要对其进行重命名。

enter image description here

在此处输入图片说明

I am using XCode 8and it is the best option I could find to change the name of my class in the whole project.

我正在使用XCode 8,这是我能找到的在整个项目中更改班级名称的最佳选择。

回答by user550088

With Xcode 9, to be released in fall 2017 - Developers would be able to - 1. Refactor their Swift code. 2. Rename Swift project classes. 3. Run multiple instances of the simulator at once. 4. Run and debug on physical devices wirelessly. 5. Access, pull, push and commit to Git directly from XCode.

使用将于 2017 年秋季发布的 Xcode 9 - 开发人员将能够 - 1. 重构他们的 Swift 代码。2. 重命名 Swift 项目类。3. 一次运行模拟器的多个实例。4. 在物理设备上无线运行和调试。5. 直接从 XCode 访问、拉取、推送和提交到 Git。

My personal favorite is the way issues are highlighted in red in multiple lines completing the sentence of the issue.

我个人最喜欢的是在完成问题句子的多行中以红色突出显示问题的方式。

This WWDC 2017 session is a good view

这个 WWDC 2017 会议是一个很好的观点

XCode is getting smarter for us.

XCode 对我们来说变得越来越智能。

回答by ApriOri

AppCodeby Jetbrains can refactor/rename both Swift and objective C classes quite easily. it's not free, but it does a great job.

Jetbrains 的AppCode可以很容易地重构/重命名 Swift 和目标 C 类。它不是免费的,但它做得很好。

回答by William Hu

  1. Find & Replace by cmd + shift + F
  2. Rename class name.
  3. If you use storyboard/Nib file, don't forget change the class you assigned in Show the identify inspectorto new class name.
  1. 查找和替换 cmd + shift + F
  2. 重命名类名。
  3. 如果您使用 storyboard/Nib 文件,请不要忘记将您分配的类更改Show the identify inspector为新的类名。

TIPSet scope under the search field for Find & Replacecan make this work clear.

提示在搜索字段下设置范围Find & Replace可以使这项工作变得清晰。