How to delete an old/unused Data Model Version in Xcode - xcode

How can I delete an old Data Model in Xcode? The option is disabled on the menu. (The models I want to delete have not been released to the public - they are interim development models.)

It's a hack, but this worked for me:
Set the Current version of the model in Xcode to one that you want to keep
Remove the .xcdatamodeld from your project (Right-click -> Delete -> Remove Reference Only)
Show the contents of the .xcdatamodeld package in the Finder (Right-click -> Show Package Contents)
Delete the .xcdatamodel file(s) that you don't want anymore
Re-add the .xcdatamodeld file to your project
This eliminates the need to manually modify any of the project metadata files.

I've just found the need to do this. I created a new model version then realised I didn't need it after all. I was surprised to find there was no way of deleting it (that I could find) from Xcode. Still, to remove it I did the following:
First I made sure it wasn't my current model version. Then I went to Finder and found my *.xcdatamodeld file. Right click and Show Package Contents on that. In there you will find the actual model file and can delete it.
This still doesn't remove it from Xcode and it will show red in the Files and Groups. To stop this from happening go back to Finder and Show Package Contents on your main *.xcodeproj file (you may want to make sure you have a backup of this first). In there open up and edit project.pbxproj do a find on your model version name, in my case "interval 8". For me it appeared on two separate lines. I removed these lines and now it's completely removed from Xcode.

This worked for me in XCode 10.3 without the ordering issue occurring when removing the whole model and adding it again:
Select any model version other than the one you want to delete.
From XCode, right-click the .xcdatamodeld file and select 'Show in Finder'.
Close XCode.
In finder, right-click the same file and select 'Show Package Contents'.
Write down the name of the model you want to remove, then from Finder, delete it.
Still in Finder, navigate to the project file (.xcodeproj).
Right-click and open with Atom or any other editor.
From the 'Project' pane open project.pbxproj file.
Remove all lines containing the model name you removed (Example: "ABC 17.xcdatamodel"). You will find two lines similar to the following:
9D88880323C545B800A789B9 / ABC 17.xcdatamodel / = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = "ABC 17.xcdatamodel"; sourceTree = "";
and
9D88880323C545B800A789B9 / ABC 17.xcdatamodel /,
Note if you find a third line it will be something like:
currentVersion = 9D88880323C545B800A789B9 / ABC 17.xcdatamodel /;
That means it is the currently selected model. Never delete this line. Just change the text to another model version.
Re-open XCode.

My answer is not issue-specific at all but it's quick and works. For those using git. You can just discard unstaged changes.
git stash save --keep-index
Then you can drop that stash with a git stash drop command if you like.

Related

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

Duplicate and rename Xcode project & associated folders [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
I would like to be able to duplicate an entire Xcode project, rename the project and the associated files without Xcode going mental, and without having to manually re-import all files to the project.
This answer is the culmination of various other StackOverflow posts and tutorials around the internet brought into one place for my future reference, and to help anyone else who may be facing the same issue. All credit is given for other answers at the end.
Duplicating an Xcode Project
In the Finder, duplicate the project folder to the desired location of your new project. Do not rename the .xcodeproj file name or any associated folders at this stage.
In Xcode, rename the project. Select your project from the navigator pane (left pane). In the Utilities pane (right pane) rename your project, Accept the changes Xcode proposes.
In Xcode, rename the schemes in "Manage Schemes", also rename any targets you may have.
If you're not using the default Bundle Identifier which contains the current PRODUCT_NAME at the end (so will update automatically), then change your Bundle Identifier to the new one you will be using for your duplicated project.
Renaming the source folder
So after following the above steps you should have a duplicated and renamed Xcode project that should build and compile successfully, however your source code folder will still be named as it was in the original project. This doesn't cause any compiler issues, but it's not the clearest file structure for people to navigate in SCM, etc. To rename this folder without breaking all your file links, follow these steps:
In the Finder, rename the source folder. This will break your project, because Xcode won't automatically detect the changes. All of your Xcode file listings will lose their links with the actual files, so will all turn red. Note: You may have to do Step 2 first, then come back to this step.
In Xcode, click on the virtual folder which you renamed (this will likely be right at the top, just under your actual .xcodeproject) Rename this to match the name in the Finder, this won't fix anything and strictly isn't a required step but it's nice to have the file names matching.
In Xcode, Select the folder you just renamed in the navigation pane. Then in the Utilities pane (far right) click the icon that looks like dark grey folder, just underneath the 'Location' drop down menu. From here, navigate to your renamed folder in the finder and click 'Choose'. This will automagically re-associate all your files, and they should no longer appear red within the Xcode navigation pane.
In your project / targets build settings, search for the old folder name and manually rename any occurrences you find. Normally there is one for the prefix.pch and one for the Info.plist, but there may be more.
If you are using any third party libraries (Testflight/Hockeyapp/etc) you will also need to search for 'Library Search Paths' and rename any occurrences of the old file name here too.
Repeat this process for any unit test source code folders your project may contain, the process is identical.
This should allow you to duplicate & rename an Xcode project and all associated files without having to manually edit any Xcode files, and risk messing things up.
Credits
Many thanks is given to Nick Lockwood, and Pauly Glott for providing the separate answers to this problem.
Duplicating an Xcode 4 Project
Renaming xcode 4 project and the actual folder
I'm posting this since I have always been struggling when renaming a project in XCode.
Renaming the project is good and simple but this doesn't rename the source folder. Here is a step by step of what I have done that worked great in Xcode 4 and 5 thanks to the links below.
REF links:
Rename Project.
Rename Source Folder and other files.
1- Backup your project.
If you are using git, commit any changes, make a copy of the entire project folder and backup in time machine before making any changes (this step is not required but I highly recommended).
2- Open your project.
3- Slow double click or hit enter on the Project name (blue top icon) and rename it to whatever you like.
NOTE: After you rename the project and press ‘enter’ it will suggest to automatically change all project-name-related entries and
will allow you to de-select some of them if you want. Select all of
them and click ok.
4- Rename the Scheme
a) Click the menu right next to the stop button and select Manage Schemes.
b) Single-slow-click or hit enter on the old name scheme and rename it to whatever you like.
c) Click ok.
5 - Build and run to make sure it works.
NOTES: At this point all of the important project files should be renamed except the comments in the classes created when the project
was created nor the source folder. Next we will rename the folder in
the file system.
6- Close the project.
7- Rename the main and the source folder.
8- Right click the project bundle .xcodeproj file and select “Show Package Contents” from the context menu. Open the .pbxproj file with any text editor.
9- Search and replace any occurrence of the original folder name with the new folder name.
10- Save the file.
11- Open XCode project, test it.
12- Done.
EDIT 10/11/19:
There is a tool to rename projects in Xcode I haven't tried it enough to comment on it.
https://github.com/appculture/xcode-project-renamer
As of XCode 7 this has become much easier.
Apple has documented the process on their site:
https://developer.apple.com/library/ios/recipes/xcode_help-project_editor/RenamingaProject/RenamingaProject.html
Update: XCode 8 link:
http://help.apple.com/xcode/mac/8.0/#/dev3db3afe4f
I am using this script after I rename my iOS Project. It helps to change the directories name and make the names in sync.
http://github.com/ytbryan/rename
NOTE: you will need to manually change the scheme's name.
I'm using simple BASH script for renaming.
Usage: ./rename.sh oldName newName
#!/bin/sh
OLDNAME=$1
NEWNAME=$2
export LC_CTYPE=C
export LANG=C
find . -type f ! -path ".*/.*" -exec sed -i '' -e "s/${OLDNAME}/${NEWNAME}/g" {} +
mv "${OLDNAME}.xcodeproj" "${NEWNAME}.xcodeproj"
mv "${OLDNAME}" "${NEWNAME}"
Notes:
This script will ignore all files like .git and .DS_Store
Will not work if old name/new name contains spaces
May not work if you use pods (not tested)
Scheme name will not be changed (anyway project runs and compiles normally)
In the example code for the book "Instant OpenCV for iOS" I have found a bash script that copies a project from a folder to another.
Doing a little research I've found a blog post from what seems to be the original author of the script: http://mohrt.blogspot.it/2009/01/renaming-xcode-project-from-command.html, where you can download the script. I gave it a try and running it from terminal like this
sh renameXcodeProject.sh <name-of-existing-folder> <name-of-folder-to-create>
works fine.
Additional info can be found opening the file with a text editor. Hope that helps
I using Xcode 6+ and I just do:
Copy all files in project folders to new Folders (with new name).
Open *.xcodeproj or *.xcworkspace
Change name of Project.
Click on schema and delete current chema and add new one.
Here is done, but name of window Xcode and *.xcodeproj or *.xcworkspace still <old-name>. Then I do:
pop install
Open <new name>.xcworkspace
One more thing to try!
When I copied all of my files, opened the project, and renamed it, everything changed to my new project name except for the test target! I got a linker error that said I was missing a file called "myOldProjectname.app". Here's what fixed it:
Click on your project settings and select your test target
Click on build settings and search for "test host"
Check those 2 file paths. Chances are that those 2 paths are still pointing at your old project name.
Hope that helps!
For anybody else having issues with storyboard crashes after copying your project, head over to Main.storyboard under Identity Inspector.
Next, check that your current module is the correct renamed module and not the old one.

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

Adding an existing implementation file to an Xcode project won't work

As I write most of my code using MacVIM, I need to add the new files to the XCode project in order to compile them into the executable. Today however I encountered an implementation file (.m) which XCode won't allow to be added. It appears light gray in the appropriate finder window as if it were already included in the project, but when I try to build, I get a linker error, stating that the symbol defined this implementation file could not be found. The corresponding header file could be added without problems.
Any idea what could have caused this problem?
Btw. I deleted a former version of the same file from the "Classes" tree before, as well as many others which were successfully re-added.
I think I saw a similar problem once with an old version of Xcode. IIRC the way I resolved it was to:
rename the source file (temporarily)
add the renamed file to the project
do a "Save As..." on the renamed file to get it back to the original name
The file is probably already in your project, but not in the target you're building. Use the Detail view and Search bubble to find it, Get Info, and in the Targets tab of the info window, check the check box for the target you're building.
The other answer (removing and re-adding) works because you end up removing it from the project, then when you re-add it, it's added to the current target by default.
I found that deleting my pbxuser file from inside the .xcodeproj solved the problem for me. There were references to the files I couldn't add in there, surprisingly. This has happened to me many times over the years.
Another trick is to:
Move the file into a different directory
Add it to the XCode project from there
Move it to the desired location
Select the file in Groups & Files
Choose File > Get Info from the menu bar. The full path will appear in red.
Press the Choose... button and select the file at the new location.
If you are using Xcode 4, you can do the following steps to add an existing file into your target:
1) Select your file in "Project navigator" view (aka. click your myfile.m file in the folder tree of Xcode)
2) Click menu item "View" => "Utilities" => "Show File inspector" (or use the shortcut "Alt + Command + 1)
3) There is one section called "Target Membership", check the target you want
I fixed this by deleting the .xcuserstate file and restarting the project. I am using a workspace file, for all it's worth.
You can find any and all referencing files via
grep -r -h [NameOfFileThatYouAreTryingToAdd] *
from within your project directory.

Resources