Unable to add datamodel in xcode4 - ios

I'm porting my iphone app to ipad, and therefore created a completely new project. After programming a while, i wanted to import the coredata model from my iphone project, so i can have the same coredata storage layout. but for some reason, xcode 4.2 wont let me use the imported model. after drag-and-dropping the versioned model (foobar.xcdatamodeld) into my ipad project (copying it to the destination), i am unable to select the current version, and the model will not show the arrow-indicator as well as no sub-models in the file-list on the left side of xcode.
even if i create a new datamodel (file -> new...), i get the same behaviour. i can't edit the model, because appearently it is not opened (clicking on the model in the file list will not change the editor window in the middle), i cannot add a version to the model (the menu item unter "editor" is not present), and i can't select any current version.
i noticed that the object inspector will state a path that is "Relative to group", with the path beeing "../foobar.xcdatamodeld" (which is "foobar.xcdatamodeld" in my iphone project), and the full path is beeing blank.
i even edited the model and xcode project files through vi, to make it look like the iphone ones, with no success.
so, right now i can't neither add a new datamodel, nor import the existing model.
can anyone help?

i have no idea if it's related, but i ran into a weird thing earlier today when copying resources from one project to another. i did the same thing (made sure i selected copy files into destination's group folder etc) and it didn't actually copy them - it was referring to the files in the project i was copying from. weirder still, the project couldn't actually "see" them (the file names were red).
i ended up getting around it by manually copying them into the "to" project's directory, and adding them from there.

Related

Copy core data file model from Objective-C app to brand new Swift 3 project

I have a first version of an iOS app written in Objective-C using core data.
I am now in the process of totally re-writing the app from scratch in Swift because the Objective-C version is very buggy.
The goal is to keep the database content in the app, after updating from Objective-C to Swift version. Users should not lose data.
In the Swift project, I used the .xcdatamodel that was automatically generated and I recreated all Entities and Relationships exactly based on the Obj-c .xcdatamodel file.
Bunddle identifier is the same for both version. In the simulator, one is replacing the other when I run projects. But the database is erased each time.
I found several topics explaining lightweight or heavy migration, but always related to a data model change inside the same project.
Is it possible to copy the old .xcdatamodel file into the new project?
I tried but without any success. Maybe problems are that files are named differently and that projects are written in different languages.
Copying a model file to a new project is literally as simple as copying the file.
If you have both Xcode projects open, you can drag the file from one project into the other. Xcode will ask what you want to do-- make sure that "Copy items if needed" is checked. Click "Finish" and you're done.
Or do it in Finder. Duplicate the old file, move the duplicate into the new project's folder, and rename it if necessary. Then switch to Xcode and tell it to add the new model file ("File" menu --> "Add files...").

Is there any better way to rename an XCode project than the given one?

The given version is described here: How do I rename a project in Xcode 5?
But, as you can see from the following screenshot^, not everything gets renamed, and if one opens package contents, directory names etc. to try to manually change all the references, the project is broken afterwards, so you have to keep the old project name for sub directories etc., which granted is not a massive problem, but is intensely irritating, and I'm not enjoying being intensely irritated at work.
^ apologies for a screenshot, but there's too much information in it to transcribe to written text. Top two-thirds of screenshot is XCode project, bottom third a Finder window.
Renaming projects in xcode in one of the most annoying things in iOS development. I assume you want to rename your app. I faced this problem once and figured out a simple, clean way to do it.
Go back to the point where everything worked.
Open project in xcode and click on the project icon in the project structure( first file)
Go to the info tab
Search for Bundle Name. Most probably it will automatically be set to $(PRODUCT_NAME) which is a shell variable that will set your app name the same as the project name.
Set it to whatever you want your app name to be
Done
Notes :
If you use custom URL Schemes this might produce an error when redirecting.
ALWAYS git or some other SVN in your projects. This will come in handy in this kind of situations

How to change the name of an Xcode file folder?

(XCODE 5)
I may be wrong in calling it a file folder, but what I'm referring to is the folder that contains all the files that is created after making a new project. In my case, I saved my project onto the desktop, and originally named it something completely different. Now I want to change its name, but before when I changed the name of the folder it didn't work when I tried to build and run my app. The other question I had was how to move it to another location because same thing happened when I moved the project from the desktop.
I was also wondering what A or M or a ? mean beside the files on the left hand panel (inside the project)
In terms of renaming the folder, you're generally fine renaming the top level folder, but it can get messy when renaming one of its one of the subfolders. If you rename the subfolders, side affects include (a) messing up links in the Xcode project; and (b) if you're using version control, losing the connection between the previous change history and the new file. But if you're talking about the top level folder under which everything for the project is included, I've never had problems renaming that.
In terms of the A/M designation, a A means that new file has been added to the project; M means that an existing file has been modified. You'll only see these when your project is under version control (which is a checkbox you can check when creating your project.)

Xcode modifies current CoreData model version at every launch

I'm using Xcode 4.6 to work on a project which uses CoreData. The data model is now at version 13 and uses lightweight migration.
My problem: At every launch Xcode seems to modify the PROJECT.xcdatamodeld/.xccurrentversion file to be set to version 1. I noticed that the modified file is automatically added to the GIT index. The changes made to this file are NOT reflected by the GUI of Xcode which tells me that my model's current version is 13. This problem started at some point during the development process (maybe at model version 7) and persists even for new model versions. The strange thing about it that even different Xcode installations on different computers show this behavior for this project. I included a screenshot of the changes made to the file.
My workaround is to reset the changes to this file at every launch of Xcode using GIT but it's very annoying. Someone got an idea how to solve this? Seems like a bug in Xcode.
Solved: The problem was an old entry in the project.pbxproj file (Open PROJECT.xcodeproj with right click -> "Show package content"). I deleted the section as shown in my screenshot and everything is running fine.
For us, what really solved the problem was:
select the data model in the Project navigator
select the configuration (Default for us)
in the Inspector -> File inspector change the data model version by clicking the small folder icon (below Location, find the red box in the screenshot below) and selection the correct .xcdatamodel file (notice no "d" at the end of the file). See the example where I've already changed from the version "1" (Notifications.xcdatamodel) to version "2" (Notifications 2.xcdatamodel visible in the screenshot).

.xcdatamodeld file not showing data model structure in Xcode

I have .xcdatamodeld file in my project but it not opening up into the data model.
When I click on the file in the left sidebar in Xcode, it continues to display the contents of the previously selected file instead of displaying the data model. Likewise, when I right click on the file and choose "Open As >", I cannot select to display it as a Data Model—nothing comes up. I checked out the code from the SVN repo and even the filer owner is not able to see it in his workspace.
This is a symptom that I have seen from time to time. In at least one case, this was due Xcode having the wrong path stored in the path component of the XCVersionGroup section of the project.pbxproj file, and having an apparently unnecessary additional name component in that section. It would probably be possible to manually edit this file, but I'm always reluctant to monkey around with the project file directly, and fortunately there's an easier way.
Navigate to your .xcdatamodeld file in the Finder. The easiest way to do this is Right click/Ctrl-click on the .xcdatamodeld file and select "Show in Finder".
Drag the file from the Finder and drop it immediately above or below the current reference to the .xcdatamodeld in the Project Navigator in your Xcode project.
Click OK to accept the import, ensuring that you are adding it to the correct targets. (Which targets are correct will depend on your project.)
You will now have two references to the same file in your Project Navigator. Clicking on either of them will now bring up the desired data model structure.
Remove the duplicate reference to the model file. Click on one of the file references (doesn't appear to matter which, though it may be better to remove the old one) and press Delete.
In the resulting confirmation dialog, be sure to select "Remove Reference" only, and do NOT move the file to the trash. (The two references point to only one actual file in the file system. Moving to trash would thus trash the only copy.)
You're now left with just one reference to the data model, and it works.
One thing that appears to trigger this bug is moving the .xcdatamodeld file in the file structure on disk. Even after correctly re-associating the file with the new location (i.e., it no longer appears in red in the sidebar), the one section of the Project file mentioned above is not correctly updated, and thus the file is not treated fully correctly as an Xcode Data Model file.
I encountered the same issue in Xcode 6.3
The only solution that worked for me was to move the .xcdatamodeld file out of my 'Resources' folder and into the project root folder in the Xcode project explorer (location on the filesystem doesn't matter)
I'm still not sure why, just moving the location of the file in the project structure causes it to not show up at all when clicked.. but apparently, at least in my setup, it doesn't like living in the Resources folder..
For some dark reasons, sometimes Xcode needs the xcdatamodeld fiel to be in the root folder.
I wrote an answer here that explain how to do this, but also a workaround to have this file where ever you would like to.
Cheers!
The .xcdatamodeld file is a package. It contains .xcdatamodel packages, one for each version of the model. Inside every .xcdatamodel there is a contents file, which is an XML with entities description. To see what is inside your packages, right-click them in Finder and choose Show Package Contents option.
Perhaps you didn't add the contents file into your repository. This way you will not be able to see your model when you create a brand new working copy from it.
I was victim of this problem today on Xcode8.
I solved it simply by placing the xcdatamodeld file outside any group in the Project navigator (left pane). As soon as I move it into a group, I can't open the little guy anymore.
I had a similar problem with Xcode 7.3.1.
It turned out to be related to the way the data model packages were configured.
I discovered that there was one embedded model package nested inside another. Let's say a top level data model called FolderNodes.xcdatamodeld containing another with exactly the same name ... FolderNodes.xcdatamodeld. Inside FolderNodes.xcdatamodeld is the actual contents file that has the model info.
The solution for me was to drag the embedded package FolderNodes.xcdatamodeld ( number 2) into the Xcode project and NOT its enclosing folder.
Apple uses the package for versioning but I think the logic associated with moving the data model file somehow breaks the original package creating a redundant wrapper.
Make sure your Version Editor is not active.
Having the Version Editor open results in the xml code to be displayed instead of the Data Model. You will also not be able to choose Data Model in the context menu of the xcdatamodeld file within the Project Navigator.
Happens on XCode 8.3 as well.
For me, moving the physical file to a different folder, then deleting the original reference, then adding it back to same place and establishing the reference again does the job.

Resources