kiran
kiran

Reputation: 4409

Adding Folder to Xcode Project is not Properly added

Team,

I created the new Project, on project folder right click open show in finder there I created "ViewControllers" Folder and again right click Add files to "ProjectName" then I added the created folder i.e., "ViewControllers" which is in blue colour "Expected yellow colour folder" that is reference to my project folder the blue colour folder is not. In blue colour folder when i try to added new file its added an empty File.

How can i reference my added folder to the Xcode project? how to avoid this blue colour folder class in my project?

Your inputs are highly appreciable.

Upvotes: 24

Views: 148219

Answers (2)

VTPete
VTPete

Reputation: 341

The only option that ever works for me is to drag and drop files and folders directly from Finder into the project hierarchy.

I have struggled with this simple task for ages. It's 2021 and the simple action of right clicking (or using the file menu) to "Add files to " just doesn't seem to ever work for me. It will add the files, but they will not be added as dependencies in the project. Their headers won't be found, etc. No option for adding groups or folders pops up.

The only thing that works for me is to open a Finder window, navigate to the directory that has the software I want to paste in and then drag and drop it into my project hierarchy. That is the only way I get the proper option for adding groups or folders. Having just spent 30 minutes trying to follow the advice above, I thought I'd post my solution.

Upvotes: 3

mxgzf
mxgzf

Reputation: 946

If your Xcode project looks like this…

Xcode project with folder reference

…then you've added your ViewControllers folder as folder reference.

To change this folder to a group follow these steps:

  • Right click on ViewControllers
  • Choose Delete in the context menu
  • Choose Remove Reference in the dialog that popped up. The folder will be removed from your Xcode project but not from the file system.
  • Then choose Add Files to <YourProjectName>… in the File menu
  • Find your ViewControllers in the file system
  • Before clicking Add make sure that the option Create groups is selected
  • Click Add

You've added your ViewControllers folder as group:

Xcode project with folder group


Important note regarding Xcode 8:

The option Create groups might not be visible right away. Apple moved this in Xcode 8 to the bottom of the Add Files to… dialog:

Collapsed options

This reveals the option Create groups:

Expanded options

Upvotes: 48

Related Questions