How to add new class file to group in Xcode?

10,216

Solution 1

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 :)

Solution 2

Step 1: Command + N to create a new class

enter image description here

Step 2: Name your class

enter image description here

Step 3: Specify the group where you'd like the class to go

enter image description here

Share:
10,216
dcgoss
Author by

dcgoss

Ethernet always wins. — Andy Bechtolsheim

Updated on July 26, 2022

Comments

  • dcgoss
    dcgoss almost 2 years

    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

  • dcgoss
    dcgoss almost 9 years
    I can't reproduce that third step. I can reproduce it most of the other types of files, but not the Cocoa Touch classes. I will add a picture to the question to show further
  • dcgoss
    dcgoss almost 9 years
    Just added some additional pictures to the bottom reproducing the issue.
  • Adrian
    Adrian almost 9 years
    Have you tried nuking derived data, restarting Xcode, and/or rebooting?
  • dcgoss
    dcgoss almost 9 years
    Have tried all 3. Also just added another edit: everything seems to work fine in Xcode 7. Seems to be an issue with 6.3.2