选择不是可以重命名为Xcode 7的类型 [英] The Selection is Not a Type that Can Be Renamed Xcode 7

查看:126
本文介绍了选择不是可以重命名为Xcode 7的类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

@interface 之后选择类名( ViewController ),尝试重命名一个类:

Trying to rename a class by selecting the class name (ViewController) after @interface:

@interface ViewController : UIViewController

右键单击,在以下错误警告窗口中选择重构 - >重命名结果:

Right clicking, selecting Refactor -> Rename results in the following error alert window:

这在Xcode 6中运行得很好,这是某种回归吗?我试过这个Xcode 4解决方案无济于事。任何人都知道有任何工作吗?

This worked just fine in Xcode 6, is this some sort of regression? I tried this solution for Xcode 4 to no avail. Anyone know of any work arounds?

推荐答案

是的,重构在Xcode 7中严重破坏。

Yes, refactoring is badly broken in Xcode 7.

我在尝试重命名属性,方法和类时发现了类似的问题。昨天我下载了7.1.1,希望到目前为止可能会有一些改进但是没有。

I have found similar problems when trying to rename properties, methods and classes. Yesterday I downloaded 7.1.1 with a hope that there might be some improvements but none so far.

我在Objective-C中的示例单视图项目中进行了一些测试Xcode 7.1.1并找到以下内容:

I did some testing in a sample single view project in Objective-C on Xcode 7.1.1 and found the following:


  1. 如果您尝试重命名具有IBOutlet关键字的属性,它将失败;

  2. 如果您尝试重命名不是IBOutlet的另一个属性,但在其声明之上,您有任何属性为IBOutlet,则重命名将失败;

  3. 如果您尝试重命名一个在IBOutlet属性下面声明的方法并右键单击.h文件中的方法,重命名将失败;

  4. 如果您尝试重命名#imports的类一个在头文件中有一些IBOutlet声明的类,重命名将失败(突出显示,因为这是原始问题的原因)。

  1. If you try to rename a property that has IBOutlet keyword, it will fail;
  2. If you try to rename another property which is not IBOutlet, but above it's declaration you have any property that is IBOutlet, rename will fail;
  3. If you try to rename a method which is declared below IBOutlet property and do it right clicking the method in .h file, rename will fail;
  4. If you try to rename a class that #imports a class that has some IBOutlet declarations in the header file, rename will fail (highlighted since this is the case, that original question is about).

幸运的是我还找到了一些解决方法:

Luckily I also found some workarounds:


  1. 如果你移动你的支柱声明在IBOutlet声明之上,重命名将成功;

  2. 如果您需要重命名IBOutlet - 您可以将其移到所有其他IBOutlet之上,并在重命名之前删除它的IBOutlet关键字。重命名将成功(并且还将在Storyboard中重命名),然后您可以添加IBOutlet关键字;

  3. 如果您将方法的声明移到任何IBOutlet属性之上,则重命名将从.h成功文件,但是,如果你在.m文件中选择时尝试重命名它似乎也有效(后一种情况即使在IBoutlet属性下的.h文件中声明方法也有效);

  4. 重命名使用IBOutlets导入另一个类的类时,可以执行以下操作 - 将另一个类的IBOutlet从.h文件移动到.m文件。然后重命名工作。或者 - 在重命名之前删除所有IBOutlet关键字,然后将其添加回来。

  1. If you move the declaration of your property above IBOutlet declarations, rename will succeed;
  2. If you need to rename IBOutlet - you can move it above all other IBOutlets and remove the IBOutlet keyword of it before renaming it. Rename will succeed (and will also rename it within Storyboard), then you can add the IBOutlet keyword back;
  3. If you move declaration of your method above any IBOutlet properties rename will succeed from .h file, but alternatively it also seems to work if you try to rename it when selecting in a .m file (the latter case works even if method is declared in .h file below IBoutlet properties);
  4. When renaming class that imports another class with IBOutlets, you can do the following - move the IBOutlets of the other class from .h file to .m file. Then rename works. Alternatively - remove all IBOutlet keywords before the rename, and then add them back after it.

注意:当我说重命名成功时,我的意思是 - 它不会显示选择不是可以重命名的类型。但是大部分时间它仍然不能顺利运行:

Note: When I say that rename succeeds, I mean - it won't show you "The selection is not a type that can be renamed". However it still does not work smoothly most of the time:


  1. 它没有显示文件中的更改,就像以前一样do;

  2. 当Xcode有未保存的更改时,它可能会抱怨文件已被其他应用程序修改过。正如我所发现的,通常你需要选择保持Xcode版本;

  3. 它可能无法重命名所有已使用文件中的属性。这是最重要的,在某些情况下会使所有变通方法无用。具体来说,我在使用上述方法重命名IBOutlet属性时已经看到了它。

  1. It does not show the changes to be made in files, like it used to do;
  2. It may complain about the fact that files have been modified by another application while Xcode has unsaved changes. As I have found, usually you need to choose "Keep Xcode Version";
  3. It may fail to rename the property in all of the files it has been used. This is the most important, which in some cases make all the workarounds useless. Specifically I've seen it when renaming IBOutlet properties with method I've described above.

希望有所帮助:)

这篇关于选择不是可以重命名为Xcode 7的类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆