45

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

6 Answers 6

42

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

Sign up to request clarification or add additional context in comments.

6 Comments

Are groups flagged with the yellow folder icon then?
Yellow folders are "Groups", they are not actual folders but references to folders/files. They exist only to organize your project in Xcode. @hinterbu
Cool, I just did some testing and understand it in full now. Thanks to both you and @DBoyer. Huge help.
Np glad to help out :) @hinterbu
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.
|
23

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.

Comments

10

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

3 Comments

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
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.
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.
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.

Comments

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 ...

Comments

0

When to Create groups ?

Creates a group structure in your project that matches the structure of the selected files and folders on disk. Xcode creates a group in the Project navigator for each folder you add, and it adds the contents of the folder to that group. Choose this option when you want the group structure in Xcode to differ from the directory structure on disk, or you want to reference files outside your project.

When to Create folders ?

Displays the folders in the Project navigator, and either copies, moves, or references files depending on the selection you make in the Action picker. In the Project navigator, each added folder points to a folder in the file system. Choose this option when you want your Project navigator folders to match the file and directory structure on disk, and to minimize changes to your project file when you add or remove files.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.