Why in Xcode, Groups can be created, but not real folders?

后端 未结 3 1476
悲&欢浪女
悲&欢浪女 2021-01-30 13:02

When doing iOS programming, it is interesting that in Xcode (4.3.2), we can create groups, such as a group call Images, and add files to it (either as a link or cho

3条回答
  •  再見小時候
    2021-01-30 13:52

    Note: In Xcode 10, the default behavior now creates a linked folder when you create a new group. The information below still applies otherwise.

    The recommended way to organize files is via groups, because it's more flexible than creating directories, and allows you to create complex file hierarchies while maintaining a totally different file hierarchy on the file system. It's simply an organization tool. That said, it is possible to turn groups into folder references, or create them initially as folder references.

    Furthermore, using groups instead of folder references gives you greater flexibility if you need to change where things are in the file system - say you have a common folder of code that you use in a bunch of different projects. Groups allow you to organize the files inside of projects as if they were in the projects, while still maintaining one copy of the code in a central location. And yes, you can do this with folder references as well, but groups are much more flexible if you later want to add other things to the same group but don't want them to be added to that common folder.

    If you want to link a group to a folder, click on the group in the project file tree and hit command+option+1. Below the drop down that'll say something like "Path: Relative to Group" on the right, there's a little white square with a grey border around it kinda icon next to the word "none". Clicking on this and then selecting/creating a folder will bind the group to the folder.

    folder reference

    Furthermore, when you drag a folder into Xcode, it will ask you if you want it to be a group or a folder reference:

    adding a folder reference

提交回复
热议问题