Adding Folder to Xcode Project is not Properly added - xcode

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.

If your Xcode project looks like this…
…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:
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:
This reveals the option Create groups:

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.

Related

How do I embed projects using Xcode 10?

I've been searching the internet for hours trying to figure this out. In previous versions of Xcode, I could drag a .xcodeproj file onto my workspace, and the groups, etc. of that project would be in the main one. That is, its sources and products would be accessible in the parent project. I mean to do this for a new private framework of mine, but it seems that in Xcode 10.2.1, this behavior is changed.
When I follow the instructions found in Apple's archived documentation (all that seems to survive), the .xcodeproj file sits alone in my file inspector. No reference hierarchy, and nothing happens when I click on it. On top of that, that project's frameworks are not accessible to the parent project.
Has anyone here figured out how this changed in Xcode 10, and what we are to do about it now? Many thanks!
This certainly feels like a workaround, but it does seem to work:
Open one of the projects you want to be in the final workspace
From the "File" menu choose "Save As Workspace…" and save it somewhere on disk
This will create a new workspace that looks identical to the Xcode project you originally opened.
From the "File" menu choose "Add files to “WorkspaceName“…" and select the next project you want in the workspace
At this point it will probably put the newly added project "inside" of the existing one in the file navigator pane. Simply drag it out to the top level and it will be on the same level as the original project. You should be able to twirl open the disclosure triangle and see the source files it contains. Clicking on the project will show the targets it contains.
Repeat as necessary for the remaining Xcode projects
As you add projects, the schemes from each project will show up in the popup menu under the scheme button in the toolbar.

Couldn't load a Xcode project with pods [duplicate]

How do I rename a project in Xcode 5?
What steps do I need to take?
In the past this was always a very tricky manual process.
Well, the answer is very very very Apple simple in Xcode 5!
In the Project Navigator on the left side, click 2 x slowly and the Project file name will be editable.
Type the new name.
A sheet will appear with a warning and will list all the items Xcode 5 believes it should change.
You can probably trust it, but you should inspect it.
The list will include the info.plist and various files, but also all the relevant strings from nib/xib files like MainMenu menus.
Accept the changes and you will get the prompt to save a snapshot of the project.
Always make a snapshot when Xcode asks, it will be useful to restore if something does not work.
Change the project name:-
Click on the target in xcode, on the right in "Identify and Type" under name change the name and press the ENTER button on your keyboard.
A window will appear confirming the change and what it will change. Once you confirm it will make the changes.
Change the root folder name:-
Go to the project directory and rename the root folder,
Open the project and u will find all the file are missing, u need to add all the files of project again
Right click the project bundle .xcodeproj file and select “Show Package Contents” from the context menu. Open the .pbxproj file with any text editor.
4>Search and replace any occurrence of the original folder name with the new folder name.
5>Save the file.
Change the Scheme name:-
rename .xscheme file
If your Project is static framework then make sure your header file has public target membership
I really recommend just opening the folder in a general editor such as Sublime Text, and doing a find/replace across the whole folder. The other methods I found were unstable, particularly when combined with .xcworkspace and cocoapods.
In Xcode 8.0, to rename your project, just go through the following instructions as described in Xcode help:
1- Select your project in the project navigator.
2- In the Identity and Type section of the File inspector, enter a new
name into the Name field.
3- Press Return.
A dialog is displayed, listing the items in your project that can be
renamed. The dialog includes a preview of how the items will appear
after the change.
4- To selectively rename items, disable the checkboxes for any items
you don’t want to rename. To rename only your app, leave the app
selected and deselect all other items.
5- Click Rename.
Source: http://help.apple.com/xcode/mac/8.0/#/dev3db3afe4f
Xcode 6 (beta 6 as of now) seems to be not very reliable with renaming projects. For me it didn't rename several of the files and groups. It also doesn't rename the physical folder the project is in. To rename my project to be sure that everything is clean I went the extra length to create a new project with the new name and copy over all the files. The assets are easy to copy but groups have to be recreated. The biggest issue with this however are CoreData data model files. Trying to simply copy this will result in a corrupt model file, even though everything looks like it is alright.
When you re-name the project name in XCode5 then info.plist entry removed from Targets --- > General ---> identity. You just need to mention it again.
In Xcode 7, renaming a project can still break your app. Make sure you backed it up before trying it.
Click on the project icon and find the project name in the inspector pane. If you change it there, Xcode will ask you if you want to rename related files. Might work. But if not, try this brute force approach:
Close Xcode
Using an advanced text editor like Sublime Text or Atom, open the
root folder. It will open the folder structure.
Perform a Global Search and Replace (it's probably cmd + shift + f), and
replace My Wrong App Name with New App. If your project name contained spaces, also search for My_Wrong_App_Name and replace
with
New_App. This changes all file contents.
Now you need to find all
the files inside the project with your old app name. Rename them
all, also the folders.
Important: Open the project file with
right click > Show Package Contents, and rename all files in there.
Reopen your Xcode project or workspace. Compile.
If you use Pods, you need to open the pods project as well and change the files in there.
Here is another great example which works well with xcode 5

How do I rename a project in Xcode 5?

How do I rename a project in Xcode 5?
What steps do I need to take?
In the past this was always a very tricky manual process.
Well, the answer is very very very Apple simple in Xcode 5!
In the Project Navigator on the left side, click 2 x slowly and the Project file name will be editable.
Type the new name.
A sheet will appear with a warning and will list all the items Xcode 5 believes it should change.
You can probably trust it, but you should inspect it.
The list will include the info.plist and various files, but also all the relevant strings from nib/xib files like MainMenu menus.
Accept the changes and you will get the prompt to save a snapshot of the project.
Always make a snapshot when Xcode asks, it will be useful to restore if something does not work.
Change the project name:-
Click on the target in xcode, on the right in "Identify and Type" under name change the name and press the ENTER button on your keyboard.
A window will appear confirming the change and what it will change. Once you confirm it will make the changes.
Change the root folder name:-
Go to the project directory and rename the root folder,
Open the project and u will find all the file are missing, u need to add all the files of project again
Right click the project bundle .xcodeproj file and select “Show Package Contents” from the context menu. Open the .pbxproj file with any text editor.
4>Search and replace any occurrence of the original folder name with the new folder name.
5>Save the file.
Change the Scheme name:-
rename .xscheme file
If your Project is static framework then make sure your header file has public target membership
I really recommend just opening the folder in a general editor such as Sublime Text, and doing a find/replace across the whole folder. The other methods I found were unstable, particularly when combined with .xcworkspace and cocoapods.
In Xcode 8.0, to rename your project, just go through the following instructions as described in Xcode help:
1- Select your project in the project navigator.
2- In the Identity and Type section of the File inspector, enter a new
name into the Name field.
3- Press Return.
A dialog is displayed, listing the items in your project that can be
renamed. The dialog includes a preview of how the items will appear
after the change.
4- To selectively rename items, disable the checkboxes for any items
you don’t want to rename. To rename only your app, leave the app
selected and deselect all other items.
5- Click Rename.
Source: http://help.apple.com/xcode/mac/8.0/#/dev3db3afe4f
Xcode 6 (beta 6 as of now) seems to be not very reliable with renaming projects. For me it didn't rename several of the files and groups. It also doesn't rename the physical folder the project is in. To rename my project to be sure that everything is clean I went the extra length to create a new project with the new name and copy over all the files. The assets are easy to copy but groups have to be recreated. The biggest issue with this however are CoreData data model files. Trying to simply copy this will result in a corrupt model file, even though everything looks like it is alright.
When you re-name the project name in XCode5 then info.plist entry removed from Targets --- > General ---> identity. You just need to mention it again.
In Xcode 7, renaming a project can still break your app. Make sure you backed it up before trying it.
Click on the project icon and find the project name in the inspector pane. If you change it there, Xcode will ask you if you want to rename related files. Might work. But if not, try this brute force approach:
Close Xcode
Using an advanced text editor like Sublime Text or Atom, open the
root folder. It will open the folder structure.
Perform a Global Search and Replace (it's probably cmd + shift + f), and
replace My Wrong App Name with New App. If your project name contained spaces, also search for My_Wrong_App_Name and replace
with
New_App. This changes all file contents.
Now you need to find all
the files inside the project with your old app name. Rename them
all, also the folders.
Important: Open the project file with
right click > Show Package Contents, and rename all files in there.
Reopen your Xcode project or workspace. Compile.
If you use Pods, you need to open the pods project as well and change the files in there.
Here is another great example which works well with xcode 5

How can I change the location of files in xcode project?

I put some files on the same level of *.xcodeproj file carelessly. When I move these files into the right location in Finder, Xcode tells me that these files are missing. So I delete the group which contains these files whose names have been read (I realize it is a mistake). And I drag these files from Finder into the xcode to build a new group. But when I try to run the project, Xcode still can't find these code. How can I solve the problem?
When you see a file that is red (or in the wrong place), you can easily correct the location of these files by using the file inspector (which appears along the right side panel of your Xcode window).
It looks like this:
Clicking on the Folder icon next to the name will bring up an open panel from which you can choose the correct location of the file.
There is an easier way to re-organize files through the Xcode project. You can use Synx, it automatically fixes file paths, through the Xcode project groups.
You can check Github page for Synx
Synx
After intalling Synx just run the command below
synx path/to/my/project.xcodeproj
I found the answer.
3 things
1
removed the reference to the red files
then dragged them back into the project
relinked all my .m and .h files just incase
2
then removed the .app reference and dragged it back in to the project.
3
removed any duplicates or red files in the build phases
Fixed
Thanks everyone for your suggestions and help
From my point of view i would definitely avoid the virtual folders in the Xcode.The disadventage of this approach is whe nthe project gets bigger and bigger you can not find corresponding files in your filesystem easy.Even you click on "Show in finder" you need to look for the file among tens of files.
My approach is creating the folder in the finder and then dragging it to project.when i need to create a new file in this subfolder is will be added there anyhow.
Drag the new files from the finder to the Xcode project file structure.
Remove the old files.
I had a lot of class and find a good solution for solve this problem :)
1- Select a file that you want to change the location (Red)
2- Select "show the file inspector" from right side in Xcode
3- Select wrong path or unexpected path and copy like this screenshot
4- Close your project
5- Go to your root project and right click on "project *.xcodeproj" and select "Show package contents"
6- Right click on "project.pbxproj" and open with TextEdit
7- In the file select "Find and replace" or click on " Option+Command+F " and find location that you copied and replace with "" empty
8- Save and open the Xcode :)

Renaming xcode 4 project and the actual folder

I know how to rename the project in Xcode 4, but how do you rename the source folder? The thing is that renaming the project in Xcode, does only rename within Xcode (Though it is progress compared to previous) - but why Xcode is not renaming the folder in the filesystem I don't know.
You can do this from within Xcode without resorting to hand editing the pbxproj file in a text editor!
Here's how:
Rename your source folder in the Finder. This will break the project initially because Xcode doesn't automatically detect when the real folders that the virtual (yellow) project folders point to are changed, so all the files inside that folder will turn red in Xcode. Don't worry about that, we'll fix it in step 3.
In Xcode, click on the (now broken) virtual folder in the left-hand sidebar and rename it to match the name in the Finder (you can actually call it anything you want, or not rename it at all, but that would be insane). That won't fix the red files inside the folder, but that's OK.
In the right-hand sidebar in Xcode, click the icon shown in the screenshot below to bring up a file dialog. Select the folder that you previously renamed. This will re-associate the virtual folder with the real folder on disk, and will automatically fix the links to all the files inside.
In your build settings, search for the old folder name and manually rename any occurrences you find. There will typically be two of them, oldfolder/prefix.pch and oldfolder/info.plist, but there may be others.
All done!
EDIT: this option is still there in Xcode 5, but is helpfully hidden by default. To show it, click the thin "Identity and Type" header in the inspector above the "Text Settings" panel to expand it.
I've done it dozens of times:
Rename the Project by clicking then editing the Title in your Xcode Project Navigator.
Close Xcode.
Rename the source folder.
From the Finder, open the .pbxproj file inside project bundle (context menu "Show Package Contents") with any text editor.
Search and replace any occurrence of the original folder name with the new folder name.
Save the file.
Open Xcode project.
Task:
Rename "Play" to "Play2" both in Xcode and in Finder
Change this:
To this:
STEPS:
// Before anything, please backup the project in Finder!
Rename project in Xcode Project navigator // Click project name then hit enter
Rename group in Xcode Project navigator // not affecting folder name in Finder
Close Xcode
Rename outer folder (left column in image) in Finder
// All above steps are straight-forward and without side effects
//
// Now comes the tricky part: rename the inner folder (middle column in image) in Finder (the one at the same level with .xcodeproj)
Rename the inner folder in Finder while keeping Xcode closed
Right click .xcodeproj, select "Show Package Contents"
Open .pbxproj file with Mac TextEdit
Search and replace all "Play" with "Play2". To guarantee everything goes right, click the arrow on the left end of the search bar and modify the search attribute. Change "Contains" to "Full word", and uncheck "Ignore case"
Save .pbxproj file
Open Xcode project and Run
Here is how to rename a project effectively in XCode4 (INCLUDING THE FILES FOLDER):
Close all open projects completely in XCode to prevent any issues
Copy the Project in question to a new Folder (IMPORTANT: KEEP A BACKUP OF YOUR OLD PROJECT)
Open the Project
Rename the Project itself in XCode4 (double click on the project name), change the name and follow the steps (yes to everything)
Go to product, manage schemes and rename the scheme (double click on the scheme name)
Close your project (make sure is completely closed otherwise the next steps will not work)
In Finder go to the Project folder and right click on the .xcodeproj file, then select the option "Show Package Contents"
Then right click on the .pbxproj file and open it with TextEdit
Replace all occurrences of the Folder Name where the projects used to live (The old project name for the new project name)
Save the file
Open the Project again and Build it!
First of - dont rename an Xcode project!!!
If you have to, the beneath could be it - I never got it to work, ended up creating a new project and started all over copying in the existing files. Xcode is so ahh.... It has so many non productive things, like also try renaming a file from "Name" to "name". Well, well have fun.
I found the answer or how to work around this: Open the pbxproj file by right clicking "Show Package Content" and in there you edit a project.pbxproj file - you have to rename a reference called path and some other stuff - just search for the folder name added "/".
That is it.
Hope it helps some one.
Here is another issue that you should be aware of while replacing values in your *.pbxproj file. If your old folder name was FooBar you will have an entry in your *.pbxproj file that looks like this:
path = FooBar
Suppose your new folder name is Foo Bar. That is, you are introducing a space. Then, this line should become
path = "Foo Bar"
If you just do a simple find and replace, the result will be a *.pbxproj file that Xcode can't parse. If your new folder name has a space and the old name didn't have a space, be sure to include the double quotes.
I am summing up for myself, after examining various answers above and trying myself.
Let's assume the current project name is ProjAbc and you want to rename it to ProjDef:
Exit Xcode of that project.
In Finder, Duplicate the folder ABOVE ProjAbc.xcodeproj for backup.
In Finder, Rename freely the folder ABOVE ProjAbc.xcodeproj if you feel you need it to suit new project name.
In Finder, Rename the source files folder parallel to ProjAbc.xcodeproj from ProjAbc to ProjDef
Open Xcode for ProjAbc.xcodeproj (in Project Navigator, all files in virtual source folder ProjAbc will be in Red color).
In Xcode, click on the (now broken) virtual folder in the Project Navigator in the left-hand sidebar and rename it to match the name in Finder - ProjDef. That won't yet fix the red files inside the folder, but that's OK.
In Xcode, (still selecting the virtual folder in the left-hand sidebar) in the right-hand sidebar, in the File inspector, click the icon shown in the screenshot below to bring up a file dialog. In the file dialog, select the folder that you previously renamed (ProjDef). This will re-associate the virtual folder with the real folder on disk, and will automatically fix the links to all the files inside.
In Xcode, in Project Navigator, click on the ProjAbc project name, and rename it to ProjDef.
You will be prompted: "Rename project content items?". Click "Rename" button.
You will be prompted: "Would you like Xcode to take automatic snapshots before Project Rename and similar operations?". Click either "Disable" or "Enable". It does not matter.
In Xcode, now open "Build Settings" inside ProjDef target (inside project ProjDef in Project Navigator). Rename both foldername and filename of both *-Info.plist and *-Prefix.pch files to contain ProjDef instead of ProjAbc.
In Xcode, in Project Navigator, in ProjDef virtual sources folder, in "Supporting Files", also rename again both *-Info.plist and *-Prefix.pch files to contain ProjDef instead of ProjAbc
In Xcode Menu, press Product/Scheme/Manage Schemes... (or click "ProjAbc"> Scheme name in Scheme Bar at left top of Xcode, and press "Manage Schemes...") and in the dialog box rename Scheme from ProjAbc to ProjDef, then press "OK" button. If Project name is composed of single word, you may run it just now!
In Xcode, edit the top comment line in Supporting Files/*-Prefix.pch file, and replace ProjAbc by ProjDef (2 times). Of course correcting this comment is optional.
Exit Xcode.
In Finder, point to ProjDef.xcodeproj and open it in text editor. (Either open it in TextWrangler.app , or, mouse right-click and in the pop-up menu press "Show Package Contents" then edit file project.pbxproj in TextEdit.app)
In the Text Editor, search "ProjAbc" (Entire Word, Match Case) which should appear once (in paragraph: /* Begin PBXNativeTarget section */ in line: productName = ProjAbc;) and replace it by "ProjDef". Indeed, project could run anyway!, so this step is optional.
if project name is composed of 2 or more separate words, like "ProjDef Geh", then you MUST do next steps: Search for the reference to the Finder folder of the virtual source files folder -
Search for the line: path = ProjDef Geh;
It will appear once, in paragraph /* ProjDef Geh */
Replace it by the line: path = "ProjDef Geh";
Save from text editor, and exit the Text Editor.
That's it. As written above, if project name is composed of single word, you can run right at end of step 11.
I found the above answers really useful, especially Nick Lockwood's answer.
I just renamed a couple of folders in Xcode 8 and encountered two more issues:
A) "missing from working copy errors"
B) Core Data crashes.
How to resolve these two issues:
A) "missing from working copy errors"
I found the below answer very useful: Swift 3 / Xcode 8 Upgrade - 100's of DerivedData files missing from working copy errors
Basically Xcode 8 has rigorous source control, which can lead to the above errors. You have to:
Clean Xcode derived data.
Go to Source Control and click Refresh Status.
Go to Source Control and click Commit; select all the files on the left sidebar of the commit menu when committing (right click -> Select All).
You'll probably get an error.
Close the Commit menu.
Refresh Status.
Close your project by quitting Xcode.
Reopen your project, refresh status, commit again.
This time the commit should work.
Click Project -> Clean.
I'm assuming that you have already enabled Source Control. If you haven't, or if you get stuck following my instructions, just follow the more detailed instructions in the link provided.
B) Core Data crashes
Renaming folders will sometimes screw up Core Data. There are several possible reasons why this is so, and below are some fixes I can suggest:
Incorrect AppDelegate model name. This was the case in my situation. Go to your AppDelegate and find let container = NSPersistentContainer(name: "YOUR CORE DATA MODEL NAME"). Make sure that the name is correct.
In the future (several years after this post, when Apple changes Core Data again) or if you're using an older version of Core Data, take a careful look at AppDelegate. There's probably something funky there that's messing with your Core Data.
Incorrect model name in xcdatamodeld. Go to Finder and open your .xcdatamodeld in a text editor.
Check the following:
<plist version="1.0">
<dict>
<key>_XCCurrentVersionName</key>
<string>YOUR CORE DATA MODEL NAME.xcdatamodel</string> <-- Make sure this is correct.
</dict>
</plist>
More detail here: Core Data model files does not load on rename
If the two things above don't work, try to 1) delete your entity and then add another entity that's identical or 2) delete your xcdatamodeld and then add another data model that's identical (and make sure that the name of the new xcdatamodeld matches what is in your AppDelegate and the rest of your code). Never do this with a live App - or if you do this, make sure to properly migrate your Core Data whilst doing so.
If you are have old reference of source project into your project, When dublicate the project (every change made affect to both proejct)
here the solution
Dublicate Project from source project
Rename source folder of source project that break reference issue.
In dublicate proejct everything goes red choose your current folder of project. (screenshot is shows in green tick answer of stackoverflow)
========================================================================

Resources