Difference between folder and group in Xcode?
Asked Answered
A

5

43

In Xcode, what is the difference between a folder and a group? Are these interchangeable terms or is there a subtle difference?

Aeciospore answered 10/12, 2015 at 17:4 Comment(0)
B
41

Groups

With groups, Xcode stores in the project a reference to each individual file.

Folders

Folder references are simpler. You can spot a folder reference because it shows up in blue instead of yellow.

There are two types of folders in Xcode: groups and folder references. You can use groups to organize files in your project without affecting their structure on the actual file system. This is great for code, because you’re only going to be working with your code in Xcode. On the other hand, groups aren’t very good for resource files.

On any reasonably complicated project, you’ll usually be dealing with dozens – if not hundreds – of asset files, and those assets will need to be modified and manipulated from outside of Xcode, either by you or a designer. Putting all of your resource files in one flat folder is a recipe for disaster. This is where folder references come in. They allow you to organize your files into folders on your file system and keep that same folder structure in Xcode.

Reference

Bombay answered 10/12, 2015 at 17:17 Comment(5)
Are groups flagged with the yellow folder icon then?Aeciospore
Yellow folders are "Groups", they are not actual folders but references to folders/files. They exist only to organize your project in Xcode. @AeciosporeBombay
Cool, I just did some testing and understand it in full now. Thanks to both you and @DBoyer. Huge help.Aeciospore
Np glad to help out :) @AeciosporeBombay
Just to add. Using Group will tell XCode to dump all the assets in the root of your .app. While using the Folder option will also make these folders inside the .app.Norsworthy
G
19

A folder in Xcode represents a folder in the file system.

A group in Xcode is a "fake" folder which does NOT represent a folder in the file system.

It is common to use a combination of groups and folders for a given Xcode project.

Garrote answered 10/12, 2015 at 17:5 Comment(0)
C
9

Xcode behavior (starting with v9) has changed and groups are now actual folders on-disk.

Crossjack answered 16/2, 2018 at 0:16 Comment(3)
But it seems that groups are not actual folders; Xcode 9 just link the group to the real folder, but actually they behave like older version. It's a feature Apple implemented to avoid have different folder struct than xcode oneSnobbish
legacy projects continue with the old behavior (folders as logical groupings) but new projects (and new groups in old projects) use physical folders for groups.Crossjack
This isn't quite true. Groups by default now track folders, but you can easily cancel that in the inspector by un-tracking the folder. When it is tracking and you rename a group, etc. then yes, it modifies the actual on-disk folder, but when you stop tracking, it behaves just like it was before... a logical grouping within the project of whatever you place under it for structural purposes only (you'll see a tiny triangle on it indicating if it's tracked or now.) So yes, they can track a folder, but they are not 'actual' folders. That's what I was calling out with this comment.Baneberry
P
5

I found that Xcode 9.2 has two versions of group when you create a group. One is group the other is group without folder. The first one also creates folder in your file system, the second one doesn't.

Petrolic answered 10/4, 2018 at 23:22 Comment(0)
A
0

I was following a tutorial and it had me drag a nested folder with a number of autogenerated Swift files with public classes and structs. I missed that I was supposed to click the "Create groups" and not "Create folder references". When I added the folders/paths using the incorrect 'folder ref', my other scripts did not see these public objects. When I did it the right way, added them using 'groups', then they were recognized in other scripts. I think this is in keeping with TheNitram's comment, that 'group' adds to the root ...

Ataractic answered 9/12, 2022 at 15:18 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.