如何将新的类文件添加到 Xcode 中的组?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/30852387/
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
How to add new class file to group in Xcode?
提问by dcgoss
I have noticed that now whenever I do command-N to create a new Cocoa Touch class in my project, it keeps adding the file outside of the project in the file tree:
我注意到现在每当我执行 command-N 在我的项目中创建一个新的 Cocoa Touch 类时,它都会在文件树中的项目外部添加文件:
The behavior I remember (I haven't touched this project in a few weeks), is that whenever I create a new class it automatically places it in the group that you are currently working in, something like this:
我记得的行为(我已经几周没有接触过这个项目了)是,每当我创建一个新类时,它都会自动将它放在您当前工作的组中,如下所示:
Is there any way to restore this behavior? Creating a new plain .swift file seems to give you the choice of picking the group, but creating a new Cocoa Touch class does not. Regardless, I don't remember having to pick the group at all, it "just worked".
有什么办法可以恢复这种行为吗?创建一个新的普通 .swift 文件似乎可以让您选择组,但创建一个新的 Cocoa Touch 类则不然。无论如何,我根本不记得必须选择该组,它“只是有效”。
Please let me know if you need any more info. Xcode v6.3.2/6.4 on El Capitan
如果您需要更多信息,请告诉我。El Capitan 上的 Xcode v6.3.2/6.4
EDIT: I have tested further, and it seems the correct behavior is observed when adding new swift files and playgrounds, but not when adding new Cocoa Touch Classes.
编辑:我进行了进一步测试,似乎在添加新的 swift 文件和 Playground 时观察到了正确的行为,但在添加新的 Cocoa Touch 类时却没有观察到。
EDIT 2: Here is photos of the file creation process and how it isn't working:
编辑 2:这是文件创建过程的照片以及它是如何工作的:
Step 1) Command-N, select new Cocoa Touch Class
步骤 1) Command-N,选择新的 Cocoa Touch Class
Step 2) Name class like usual:
步骤 2) 像往常一样命名类:
Step 3) Here is where the problem seems to lie. It gives me the option of placing where I want my files to be saved to on the disk, but it isn't allowing me to choose a group or target:
第 3 步)这就是问题所在。它让我可以选择将文件保存在磁盘上的位置,但它不允许我选择组或目标:
I also discovered that clicking the Options
button on the bottom seems to bring up the group and target selection pane, but they are grayed out and cannot be interacted with:
我还发现单击Options
底部的按钮似乎会调出组和目标选择窗格,但它们是灰色的,无法与之交互:
EDIT 3: Just tested same action with Xcode 7 and Xcode 7 gets it right. Seems to be some kind of bug with Xcode 6.3.2/6.4
编辑 3:刚刚用 Xcode 7 测试了相同的操作,Xcode 7 就正确了。似乎是 Xcode 6.3.2/6.4 的某种错误
回答by Mihai M.
I had the same problem in Xcode 6.4. Just create a new Cocoa Touch class in your project and after that, delete the reference to this file(delete->Remove Reference). After that go to File->Add File to your project, find your file in project folder. There you will be able to selecte target project in select the Group. I think it will help you :)
我在 Xcode 6.4 中遇到了同样的问题。只需在您的项目中创建一个新的 Cocoa Touch 类,然后删除对此文件的引用(delete->Remove Reference)。之后转到文件->将文件添加到您的项目,在项目文件夹中找到您的文件。在那里您将能够在选择组中选择目标项目。我认为它会帮助你:)
回答by Adrian
Step 1:Command + N to create a new class
第一步:Command + N 创建一个新类
Step 2:Name your class
第 2 步:为您的班级命名
Step 3:Specify the group where you'd like the class to go
第 3 步:指定您希望课程所在的组