Can't edit xcdatamodeld in xcode4 momb - iphone

I renamed my project.. and step by step I renamed all the targets, AppDelegate classes etc. Anyway it builds now but crashes as it can't find the .momd in the below code:
NSURL *modelURL = [[NSBundle mainBundle] URLForResource:#"MyApp" withExtension:#"momd"];
How do I get it to 'refresh' or build this momd file again? I have read various potential solutions involving adding a version on the .xdatamodeld file but heres the other thing.
When I click on the .xdatamodeld file it doesn't open up the editor anymore. It just does nothing. Right click bring me zero options.
I tried deleting the xdatamodeld file and creating a new one, but it has the same problem. When I press on it it doesn't open the editor.
When I create a brand new core data xcode project template, it does open the editor when I press on it. What am I doing wrong here?

I re-added the .xcdatamodeld file to my project and deleted the old reference. Works again now.

I'm still using Xcode 3, but when I double-click an .xdatamodeld file, it just opens the organizer. If I double-click an .xdatamodel file, it launches the project. This is probably because the xdatamodeld a folder, not a single file. It sounds like your problem is that the project file has lost its tracking to the mom you're using.
Here are some notes I made during past troubleshooting:
Troubleshooting dbase access — getting the right mom:
The first thing to suspect is that the managedObjectContext is not pointing to the correct data model (or managed object model, “mom”). (Actually, you are probably using the type:#“momd”, but it’s the target mom that’s been lost.)
In your app delegate, look for the accessor method managedObjectModel (created by Xcode when you stipulated Core Data store upon creating the project). Put a breakpoint in this method at the line that returns the mom.
Execute the program, and when it hits the breakpoint, go to the debugger model, and type “po” followed by the name of the mom variable being returned. (This is gdb’s “print object” command.)
What prints out will include “entities {” followed by a description of the entities in your data model. If nothing follows the brace, a blank mom is being returned — you’re not accessing the correct data model.
If clicking on the xcdatamodel in Xcode shows the full data model as expected, is it enclosed in an xcdatamodeld? That’s a sort of bundler/router/path file, and it may have lost its way. Do this:
- First, is the current xcdatamodel, the one with the green check icon, the first one? If not, drag it into first place, then test the app again.
- In Finder, make a copy of your xcdatamodel elsewhere for safekeeping.
- Get rid of the xcdatamodeld, in Finder and/or Xcode (I’m not sure which order I did this in). When done, it should not appear in Xcode.
- Drag the xcdatamodel (the one in the project folder) from the Finder to Xcode’s Groups & Files pane for the project, and choose the option that makes a copy for the project.
- Select the xcdatamodel, Design>DataModel>AddModelVersion. Now you should have a new xcdatamodeld file.
- Run the test again, doing the gdb print object command at breakpoint. Hopefully you’ll get a nice long printout, representing your data model.
- In future, avoid grouping the xcdatamodel/d files into a folder in Xcode. That seems to confuse things.
Examining the contents of the xcdatamodel/d files in Finder:
These are actually folders in disguise, as you will see if you remove their extensions. The guts of the data model is a plist, which you can open by double-clicking.
If you do this, test your app afterward and make sure it is still able to access your database. If not, follow the steps above.

I was in same situation, and finally fixed.
In my case, problem come from Xcode project group property: path.
Check path property of your project group that has xcdatamodeld file.
In my situation, it was different from xcdatamodeld file really exists,
and path of xcdatamodeld file was ../Model/XX.xcdatamodeld (example)
Anyway there were no problem, but someday I removed directory that is group's path property.
So Xcode couldn't find xcdatamodeld file. I add new xcdatamodled file, but this situation repeated.
Check if your xcdatamodeld file really exists in your project setting.

The solution for me was to revert back to a working copy of my .xcdatamodeld. Then, instead of renaming it via finder or the navigator pane of XCode 4, I selected the .xcdatamodeld file in the left navigation pane and edited the .xcdatamodeld's group name in the right pane of XCode 4 under the identity heading at the top.
Once I changed the name there to match my new project name, XCode automatically updated the name of the file on the file system for me.
I did not have to edit the path property as moon6pence suggested.

Related

XCode buggily loading images that aren't in my project folder

For some reason, XCode is acting up really oddly. I have been testing XCode's ability to load images with the -hd suffix, and realized that Xcode will load a file "welcomeBackground.jpg" regardless of whether it is actually in my project folder.
See, this code below will not crash when compiled. And this is the first screen that is displayed when the app loads. I deleted the file "welcomeBackground.jpg" from my project folder, and XCode still loads the file as if it were there.
This is really freaking me out. Please help?
I am 200% sure I deleted the file from my project folder even and yet Xcode does not crash on line 35.
EDIT: To repeat, things I have tried/checked
- Cleaned project
- Deleted Derived Data
- Checked for hidden files in project folder
- Deleted app from iPhone and re-run from XCode
- Deleted the files from my project folder
- Loaded another image "sadhieia.png" and crashed Xcode
because Xcode couldn't find the file (as it does not
exist), and then tried "welcomeBackground.jpg" again
and Xcode somehow finds it.
And yet, the background still loads...
In Cocos2d, if the specified image is not in your folder, it'll not crash. Instead, it'll return nil to your CCSPrite *background.I suggest you Don't use Camelcase for images. Use lowercases or underscores. Try deleting Derived Data. See this for how to delete derived data.
Scroll the project navigator down to the bottom, to "Products," then click the disclosure arrow to show your application.
Right-click the application and choose "Show in Finder" from the contextual menu that appears. A Finder window is displayed containing your application.
Command-click the title of that window; another contextual menu appears. From that, choose the folder "Derived Data." The Finder then displays a window for that folder.
In this window, you'll see a folder whose name is that of your application, followed by a long string of letters. Trash it. If you see multiple folders bearing your application's name, trash them as well.
Rebuild your project. That should take care of the issue.
This might be a slash and burn approach, but it's solved a lot of quirky project-related issues I've experienced in Xcode after attempting to clean.
Clean your project; your image file is still cached in the build folder.

XCode - Indexing failed in one file

This issue is not a major issue but has certainly made the process consume more time. When I build my application, indexing fails in one and only one file (.m file if it matters).
There is not intelligence, no color on global variables and most of the code except for important keywords are black in color. Since there is no intelligence, whenever I need to make changes, I have to see other files for doing the changes.
this happend for me when the file was not included in the target.
Method 1:
- Go to your project (the very first item in the project list) (cmd-1)
- select your target
- open tab Build Phases
- add your .m file in Compile Sources
Method 2:
- select your .m file
- show Utilities Pane (the one on the right side)
- first tab: show the file inspector (cmd-option-1)
- check the target in Target Membership
Here are the steps I follow when I face such a situation :
Clean the project, in Xcode menu Product -> Clean
Close the project
Open Organizer and go to Projects tab, select the project
Remove all derived data (the buttons are on the main view : Derived data and Snapshots)
Remove the project from the list on the left (select it and press backspace)
Finally close Xcode, launch it again and reopen the project
These steps will make Xcode rebuild the index for the whole project.
If indexing fails, try cleaning the product (or entire build folder). If that doesn't help, close Xcode, remove the DerivedData folder (you can find the location in the preferences "Locations" tab), and start Xcode again.
The indexing process will then try to re-index your files.
Hmm. Considering the normal Clean or Delete Derived Data solutions haven't worked, my next steps would be:
Copy the contents of the .m to the clipboard.
Delete the .m from your project (including sending the physical file to Trash)
Delete Derived Data
Try to compile the project (I know it will generate errors most likely, but let it do this).
Create a new .m file and paste the code back in.
Compile and run the project.
Delete Derived Data again to force a reindex.
Close XCode, reopen it.
Now hopefully it should be indexed. If this still doesn't work, try renaming that class (the .h and .m), see if it indexes, then rename it back again.
Try Product > Clean (XCode 4).
This can happen sometimes, it's annoying. If you get desperate, try creating a new project in a different location and copying the source files over.
I found solution to my question. Actually a localized file of that file was being created in en.proj folder, where indexing failed. So, I just copied that file into project main folder and deleted it from en.proj folder. It works fine now. I can see everything indexed.
Search for "GCC_INCREASE_PRECOMPILED_HEADER_SHARING" in your project build settings
Change 'increase sharing for precompiled header' from NO to YES
Hope this helps.
Go to Editor -> Syntax coloring, and change it to objective c. It might do the trick.

Could not insert new action connection Error

I get this error, when try to create new action for UIButton by dragging blue arrow from UIButton to my header file (you know, this new feature of XCode 4...)
When I create action in code by myself and connect it in old way, simply by dragging from button to File's Owner, it's works well
Here's screenshot:
Make sure your .m file exists in the project and on disk. Make sure it is correct with an #implementaiton-#end block. Open it in Xcode, close it, if the error persist, restart Xcode.
Xcode is trying to write to EditPUViewController.m (in the dealloc method etc.) but could not find it.
Also, it always helps to hard-clean the project with ⌘+⌥+⇧+K.
Try this:
Open Organizer then Project Tab.
Clear the "Derived Data". Xcode should re-index your project then and code sense should work. At least worked for me.
I had a comparable problem when trying to connect an action. To solve it I manually added the IBAction and then XCode allowed me to connect from the button to the code.
Go to Xcode -> preferences -> location tab -> derived data -> clear derived dat.
I ran into this issue myself but none of the methods presented here worked for me. The error described in the question above occurred when I tried to create an IBAction in my view's header file (.h), whereas to my implementation file (.m) I couldn't even drag a line. (Xcode wouldn't even show this little popup where you can name your action.)
After trying for hours I figured that the reason why I couldn't create the IBAction was because I had removed the very last line from my .m file. Xcode automatically adds an extra empty line after the #end delimiter when you create a new Objective-C file.
Don't ask me why - but if you remove that line Xcode doesn't let you create any actions or outlets. (This is obviously an Xcode bug.)
I noticed that .m file was moved inside en.lproj folder.
Just delete (reference only) the .m file from the Xcode and moved .m out of the en.lproj. Add it again.Don't worry, you will get all your connections back.
It will fix the issue.
I recently came across this problem. I soon realized that the cause had been my own doing.
I had previously disabled XCode indexing (which used to take forever & eat up my RAM), using the below code in a terminal window:
defaults write com.apple.dt.XCode IDEIndexDisable 1
To revert XCode to its default state, i used the following line in a terminal window:
defaults write com.apple.dt.XCode IDEIndexDisable 0
Voila! All's well again..
I got the same error. Restarting Xcode did not fix it for me (I didn't want to reboot). The file was also not in the en.lproj folder (nor in the usual project folder after I deleted it from within Xcode). The fix for me was to re-create the file with a different name (Using different case in the filename alone was not enough to fix it... must be a different name entirely).
I ran into this problem when I created a class, deleted it and then created a new one with the same name. The workaround was not to reuse the name of the deleted class, but use a new one. Thus, I'd say it's a bug on the XCode side.
Remove the newly created class (don’t delete it, just remove link and then re-add it);
Save Xib file;
Restart Xcode;
You may want to delete Derived Data as well if it does still not work.
This seems because of XCode is missing reference or need to refresh manually.
In my case, removing the reference of the nib(.xib) and adding it again solved the problem.
In my case I had by accident selected the arm64 build. When compiling I got an error but I did not notice that since I was working with the UI trying to connect an action.
The error however was exactly the same. After changing to another architecture so the project compiled I could connect the action by holding the ctrl button as usual.
user2175983 and AstroCB answer's worked well for me:
Just delete all Derived data by running this command line in a terminal:
rm -frd ~/Library/Developer/Xcode/DerivedData/*
Restart Xcode
I just deleted the reference to the file in the Xcode project and then re-added the file back to project from the finder...
In Xcode 9 I had the same error after moving .m files in project from one directory to another. Deleting references to .m files and add them again did solve the issue.
I found the ANSWER. When you create a new file (Objective C files) for each view controller, you must check by clicking the box, next to your project name. So that your project includes this file. Otherwise, this error will persist, because your project hasn't connected to the file even though it created it.

XCode uses an .xib not inside the project folder

I went back to an old project and recompiled it for OS 4.1 succesfully and ran it. I was asked to add a fourth tab to the Tab Bar, but I could not set its class to the newly added ModelsVC.h/.m. [edit: because it did not appear in the class dropdown, but the other viewcontrollers were there.]
I moved the project folder to a backup folder and unzipped a months old backup of the same project. It compiles and runs until the end of viewWillAppear for the first (default) view connected to the first tab, and then does nothing more. It is still running, but nothing is shown and nothing happens.
In the console, it says "Unknown class ModelsVC in Interface Builder file."
The problem is, that class didn't exist two months ago, so why should this way old project complain about it or even know about it?
I'd like to know where to look / tell XCode to use the .xib that is inside the project folder it is currently compiling.
And if it's path-related, how do I check what paths XCode looks in when a project is loaded/compiled?
For Xcode to run a .xib file inside the project folder, You can just open your xcode, add existing file and it is there.
I think the problem why the old project still runs is that it builds incrementally. That means when it builds the first time, the .xib file was there, and when it build the second time, it doesn't need to add and build the .xib file any more. So, in the second build, even if you delete and move out the .xib file, I think it still can build
Seems a 'sloppy copy' for whatever reason (such as a quick backup to try something experimental) of a project folder causes confusion. See this.

Localization of the iPhone Settings.bundle

For some reason I cannot get the Settings.bundle to recognize my additional languages. I must be missing something obvious, but I just cannot figure it out. Here's what I've got:
Project Structure in XCode:
Root.plist file:
Root.plist file http://img227.imageshack.us/img227/571/screenshot20100624at334.png
French Root.strings file
french Root.strings file http://img121.imageshack.us/img121/571/screenshot20100624at334.png
From everything I've read, I believe the project structure is right. The StringsTable in the Root.plist matches the name of the individual .strings files, and the Key for each item in the Root.plist has a match in the .strings files as well.
Why don't I see French text in my settings when I change the default iPhone language?
Thanks in advance!
For me, the problem was leaving off a semi-colon!
In localizable.strings, you get a runtime error if you omit the ";", but in Root.strings, you don't get any warnings, you can run it fine, but it just won't work!
So double-check to make sure you punctuate each key:value pair with a semi-colon!
I'll go ahead and answer my own question since I solved the problem myself through testing and failing. Hopefully this will help someone else in the future.
First, I think my Root.plist file may have been corrupted. I'm not exactly sure why, but I completely deleted the Settings.bundle, and re-created it to be sure.
Second, and perhaps most importantly, the main issue was the "key" in the root.strings file didn't match to the "key" field in the Root.plist, it actually matches the "Title" field.
Once I made those changes to the Root.strings file, it all started to work.
All you have to do is keep (or Add, if it's not there) "Strings Filename" in the Root.plist, after your settings.
Then, add Value "Root" (or, the name of your file and the translations) to make the created lang.lproj translations functional.
In my case, it appeared as if "Strings Filename" was set to "Root" in the Property List View of Root.plist, but when viewed the file in Source Code View, it was actually "StringsTable" pointing to "Root". The solution is to add another entry where "Strings Filename" points to "Root". (I also tried deleting the previous entry, but then it stops working, so you need both.)
In Xcode 5 there is still no obvious way to localize the Settings.bundle.
The problem
Xcode doesn't allow you to localize a file that is only shown because it is a file inside a folder that's directly shown in Xcode (hence the blue folder icons in the tree).
The Solution:
right-click the Root.strings file and select "Show in Finder"
List item
move the Root.strings file one folder up, so that the en.lproj folder is empty and the
Cmd-Drag the Root.strings file is next to the Root.plist.
delete the now empty en.lproj
go back to Xcode, notice that the tree will reflect the changes you now made
cmd-drag the file in the tree outside to outside the settings-bundle, so that it appears next to your source-code.
Do not copy the file
a dialog will appear asking you what to do with the file.
DO NOT select the checkbox to copy the file (you need this to be a reference)
DO NOT select a target to include the strings-file (the settings.bundle is already assigned to the correct target)
in the file inspector you can now choose to localize the file and to add languages to the localizations. The files will be placed correctly inside the settings.bundle and the tree will automatically reflect these changes, too.
After some repeated tries to activate localization,following steps worked for me:
Close xcode
Drag and duplicate the settings bundle onto the desktop (or wherever)
Open bundle contents
Drag Root.strings into
the en.lproj folder
Duplicate the en.lproj folder and rename to
whatever language you want (using 2-letter code ie fr.lproj)
Replace the original settings bundle with the new one(without
opening xcode).
Now Open xcode and the new files and folders
should be there
Now delete the older app and run xcode,Works fine in simulator and on device.
NOTE:Closing xcode,updating of duplicated setting bundle outside xcode and replacing updated back only will help.