[英]If I have multiple classes in one file, is there a tool to make them into separate files?
Some colleagues, now departed, had the habit of adding new classes within a related class file. 现在已经离开的一些同事有在相关类文件中添加新类的习惯。
This makes refactoring painful. 这使得重构很痛苦。
Is there a tool, perhaps within XCode or AppCode or just a simple script, that will split up these monster files? 有没有可能在XCode或AppCode中或者只是一个简单的脚本中的工具,可以拆分这些怪物文件?
It appears there is a tool to help with this in AppCode, but it only semi-automates the process. 在AppCode中似乎有一个工具可以帮助您解决此问题,但它只能使过程半自动化。
I'm using AppCode 2.0, I don't know if the same tool is available in AppCode 1.x. 我使用的是AppCode 2.0,我不知道AppCode 1.x中是否提供了相同的工具。
To extract one class from a file to a new file, right-click the @interface
or @implementation
line and select Refactor > Move. 要将一个类从文件提取到新文件,请右键单击@interface
或@implementation
行,然后选择Refactor> Move。 Alternatively press F6 on that line. 或者,在该行上按F6。 You can now enter a new file name, though you probably want to copy+paste the class name in here. 现在您可以输入一个新的文件名,尽管您可能想在此处复制并粘贴该类名。 At this point you can also select any defines you want to move. 此时,您还可以选择要移动的任何定义。
I have done some work on a script to extract all classes in a file. 我已经完成了一些脚本工作,以提取文件中的所有类。 I'd love to share this one day, when I get the chance to remove our clients code from the unit tests! 有一天,我有机会从单元测试中删除客户代码,我很乐意分享这一天!
I don't think so there is any tool for this. 我不认为有为此目的的任何工具。 However you can write your own osx application for doing the same. 但是,您可以编写自己的osx应用程序来执行此操作。
The application will ask to browse the file, and it will search for @interface....
@end and
@implementation....~@end` and will create a file from this. 该应用程序会要求浏览文件,它会搜索@interface....
@end and
@implementation ....〜@ end`,将创建该文件。 If a single file contains two classes then it will result in for files (two headers and two implementation). 如果单个文件包含两个类,则将生成文件(两个标头和两个实现)。 Then the original file can be deleted manually or automatically. 然后可以手动或自动删除原始文件。
I think this above task can be completed in few hours. 我认为上述任务可以在几个小时内完成。
Here you can go for save the original file in a folder, just in case you want to rollback. 在这里,您可以将原始文件保存在一个文件夹中,以防万一您要回滚。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.