42

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

Lucas
  • 523
  • 2
  • 10
  • 20
hinterbu
  • 747
  • 2
  • 7
  • 12

5 Answers5

39

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

Rashwan L
  • 38,237
  • 7
  • 103
  • 107
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.

DBoyer
  • 3,062
  • 4
  • 22
  • 32
9

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

Stanislav Pankevich
  • 11,044
  • 8
  • 69
  • 129
software evolved
  • 4,314
  • 35
  • 45
  • 1
    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 one – Rico Crescenzio May 28 '18 at 11:50
  • 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. – software evolved Jul 07 '18 at 15:46
  • 3
    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. – Mark A. Donohoe Jan 20 '20 at 19:26
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.

code4latte
  • 560
  • 9
  • 9
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 ...