简体   繁体   English

如果我在一个文件中有多个类,是否有工具可以将它们分成单独的文件?

[英]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.

相关问题 为什么在一个源文件中有多个类? - Why have multiple classes in one source file? 如果两个方法互相调用,但又不想在头文件中将它们之一公开,该怎么办? - What can I do if two methods call each other and I don't want to make one of them public in the header file? 在目录中搜索具有特定文件扩展名的文件,然后将它们添加到数组中,然后运行其中一个 - Search a directory for files with a certain file extensions and then add them to an array, then run one of them 如何为多个 nib 文件 iphone 设置一个视图控制器 - how to have one view controller for multiple nib files iphone 我只能将委托逻辑分离到一个类文件吗? - Can I separate the delegate logic to one class file only? 将一个单独的文件过渡到弧 - Transitioning one separate file to arc 一个UITableView中有多个UITableViewCell类? - Multiple UITableViewCell Classes in One UITableView? 如何为给定的ViewController提供备用nib文件并即时更改它们? - How can I have alternate nib files for a given ViewController and change them on the fly? 与多个类一起使用Xib - Working with One Xib with Multiple Classes 当在不同的视图控制器中实例化为单独的对象时,如何具有多个相同更新的对象副本? - How can I have multiple copies of an object that are identical update while instantiated as separate objects in different view controllers?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM