Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add new class file to group in Xcode?

I have noticed that now whenever I do command-N to create a new Cocoa Touch class in my project, it keeps adding the file outside of the project in the file tree:

enter image description here

The behavior I remember (I haven't touched this project in a few weeks), is that whenever I create a new class it automatically places it in the group that you are currently working in, something like this:

enter image description here

Is there any way to restore this behavior? Creating a new plain .swift file seems to give you the choice of picking the group, but creating a new Cocoa Touch class does not. Regardless, I don't remember having to pick the group at all, it "just worked".

Please let me know if you need any more info. Xcode v6.3.2/6.4 on El Capitan

EDIT: I have tested further, and it seems the correct behavior is observed when adding new swift files and playgrounds, but not when adding new Cocoa Touch Classes.

EDIT 2: Here is photos of the file creation process and how it isn't working:

Step 1) Command-N, select new Cocoa Touch Class

Step 2) Name class like usual:

enter image description here

Step 3) Here is where the problem seems to lie. It gives me the option of placing where I want my files to be saved to on the disk, but it isn't allowing me to choose a group or target:

enter image description here

I also discovered that clicking the Options button on the bottom seems to bring up the group and target selection pane, but they are grayed out and cannot be interacted with:

enter image description here

EDIT 3: Just tested same action with Xcode 7 and Xcode 7 gets it right. Seems to be some kind of bug with Xcode 6.3.2/6.4

like image 915
dcgoss Avatar asked Jun 15 '15 18:06

dcgoss


1 Answers

I had the same problem in Xcode 6.4. Just create a new Cocoa Touch class in your project and after that, delete the reference to this file(delete->Remove Reference). After that go to File->Add File to your project, find your file in project folder. There you will be able to selecte target project in select the Group. I think it will help you :)

like image 130
Mihai M. Avatar answered Oct 20 '22 04:10

Mihai M.