简体   繁体   English

你如何在 XCode 中使用组?

[英]How do you use groups in XCode?

I started using groups in Xcode the same way I use packages in Java or namespaces in C++, even though groups have no effect on the language.我开始在 Xcode 中使用组,就像在 Java 中使用包或在 C++ 中使用命名空间一样,即使组对语言没有影响。

Then I discovered Smart Groups and realised that it's sort of pointless to have my code neatly organised in "folders".然后我发现了 Smart Groups 并意识到将我的代码整齐地组织在“文件夹”中是毫无意义的。

Do you use groups?你使用群组吗? If so, how and why?如果是这样,如何以及为什么?

Groups are just an organisational tool, and you can use them in the way that is most logical to you.群组只是一种组织工具,您可以按照最合乎逻辑的方式使用它们。

Often developers will put their Model, View and Controller classes in separate groups.开发人员通常会将他们的模型、视图和控制器类放在不同的组中。 You might also want to put header files in their own group to reduce clutter.您可能还想将头文件放在它们自己的组中以减少混乱。

I create a group for "utility" classes like categories, and a group for each main component of the application, for instance "Inspector" or "Preview".我为“实用程序”类(如类别)创建一个组,并为应用程序的每个主要组件创建一个组,例如“检查器”或“预览”。 In those groups, the classes are further organised into Model, View and Controller groups.在这些组中,类被进一步组织成模型、视图和控制器组。

It's up to you though, just do whatever feels natural.不过,这取决于你,做任何感觉自然的事情。

如果您使用单元测试,这些也可以放在他们自己的组中。

As mentioned by others, I use groups for Model/View/Controller and for unit testing.正如其他人所提到的,我将组用于模型/视图/控制器和单元测试。

I use groups also for Doxygen documentation ( doxyfile configuration file and .dot pictures) and for embedded applications such as ffmpeg source code.我还将组用于 Doxygen 文档( doxyfile配置文件和.dot图片)和嵌入式应用程序,例如ffmpeg源代码。

In the Info window for a group, you can set the group to correspond to a real folder on disk.在组的信息窗口中,您可以将组设置为对应于磁盘上的真实文件夹。 Then, when you create files in your project by right-clicking on the group and choosing “Add New File”, Xcode will create the files in the group's folder.然后,当您通过右键单击组并选择“添加新文件”在项目中创建文件时,Xcode 将在组的文件夹中创建文件。

I do this for my test case classes.我为我的测试用例类这样做。 You can do it for any set of classes you want to keep both in their own group and in their own folder.您可以为要保留在他们自己的组和他们自己的文件夹中的任何一组类执行此操作。

Groups are simple.组很简单。

The only use I can find for them is bypassing the 10-object limit.我能找到的唯一用途是绕过 10 个对象的限制。

Ex:前任:

VStack {虚拟堆栈{

Group {
    
    Text("Hello 1")
    Text("Hello 2")
    Text("Hello 3")
    Text("Hello 4")
    Text("Hello 5")
    
}

Group {

    Text("Hello 6")
    Text("Hello 7")
    Text("Hello 8")
    Text("Hello 9")
    Text("Hello 10")
    Text("Hello 11")
}

} }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM