Turn off codegen for XCode CoreData model - xcode

Making CoreData model in XCode with already declared classes by myself, compiler code generated duplicates for me. How get rid of that?

In the Data Model editor, change the Codegen option in the data model inspector on the right to "Manual/none":
Sadly, as far as I know, you will have to do this for every Entity separately: there is no overall override.

You can disable all automatic code generation by setting the "tools version" for the data model file to Xcode 7.3. This won't have any other effect on the model-- there are no changes to the file format.

Related

Add CoreData Model shows "Deprecated Feature: Transient Inverse" warning

Using Xcode 10 (iOS project), I'm updating my CoreData model based on the current Model we have and I'm getting the following warning:
"Deprecated Feature"
Transient Inverse feature requires macOS deployment target 10.4 or earlier
(the warning is on the new Model I just created)
The project compiles and runs and is an iOS project not a macOS project. At this point i've literally just created the new model not added any new entities or attributes to it.
Any pointers would be much appreciated
Check all the relationships you have.
Uncheck the option transient.
Then the message disappears.
This warning appears when one or more relationships in your Core Data model have 'Transient' property checked.
In my case this was the way to fix the problem:
Click on your warning in Issue Navigator
Xcode will guide you to your "problematic" relationship
Check properties of the relationship in Data Model Inspector (see picture above)
If everything seems ok with that relationship check the inverse part (entity that relationship is referring to)

Adding Custom Objects in Xcode 4.3

I'm working with Objective-C and Xcode for about a year. I customise a lot of generic objects. Few days ago one of my friend asked me a question, but I couldn't answer him. So I try to do something my self. For example:
I created this Custom View:
How can I add this View to the Object Library?. Here:
I don't really know why do I need this. But I decide to figure out how to do this. I hope you could help me with this.
Thanks in advance!
I don't think this will work. You are putting buttons on "top" of a custom view placeholder. The custom view placeholder is used to be able to use - yeah you guessed right - custom user defined views.
So of which class would your view-with-5-buttons-on-top be? I think you are running into a dead end, because that's just not the way to do it in Xcode. If you want to design your custom view graphically, just create a NIB file for it.
I don't think that you can add your own view objects into the object library. Everything I know of are user-defined code snippets which will show up on the right.
Edit
There were things called IB plugins in Interface Builder and Xcode versions prior to 4.
Those were discontinued in Xcode 4 as can be read here for example :
http://xcodebook.com/2011/03/no-interface-builder-plugin-support-in-xcode-4/
Further searches for IB plugin gives a lot more guys telling the same.
Best,
Flo

Could not find the conceptual model type

I have two Entity Data models within a MVC3 project A and B.
I have recently added the new entity data model B to deal with some new functionality, the issue is that now the existing code has stopped working and I am getting the following error when trying to access code within entity model A.
The error message is:
Could not find the conceptual model type 'project.models.Bclass'
I do not understand why it is this new functionality has affected the current code seeing as entity model A has not change in any way. And functionality B is in a separate class and does not interfere with model A.
When the new code is removed from the project and entity model B is excluded then the code works as it should.
Here is some of the stacktrace from the error:
Exception : Could not find the conceptual model type for 'Project1.Models.CrossSession'.
Application Class - method : System.Data.Metadata.Edm.MetadataWorkspace -- GetEdmSpaceType
User : temp.user
Url : http://localhost/project1/auth/message
Stacktrace : at System.Data.Metadata.Edm.MetadataWorkspace.GetEdmSpaceType(StructuralType objectSpaceType)
at System.Data.Entity.Internal.InternalContext.UpdateEntitySetMappings()
at System.Data.Entity.Internal.InternalContext.TryUpdateEntitySetMappingsForType(Type entityType)
at System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type entityType)
at System.Data.Entity.Internal.Linq.InternalSet`1.Initialize()
at System.Data.Entity.Internal.Linq.InternalSet`1.get_InternalContext()
Solution found. It appears in some cases (randomly) there is a mix up in the code generated by the entity framework. This is apparently a known bug and a fix should be coming in future releases. In the mean time the way around this is to move the efm to a separate class within the solution.
One possible explanation is that if you use the database first approach and forget to add the Entity classes, you will get this error.
i.e. (from the guide linked below)
Right click on the model’s designer surface.
From the context menu, choose Add Code Generation Item.
In the Add New Item dialog that opens, select Data from the list of installed templates types on the left.
Choose the ADO.NET DbContext Generator then click the Add
button.
I normally use Julie Lerman's guide; https://msdn.microsoft.com/en-us/library/jj206878(v=vs.113).aspx
Solved this by updating EntityFramework to the latest version (6.0)
http://nuget.org/packages/EntityFramework/.
After installing it regenerate the models and it will work ;)
I had the same problem with 2 different .edmx files in the same project.
For the first .edmx model I had used "Add Code Generation Item", for the second model I hadn't. The project was building correctly but throwing that exception on runtime.
I solved generating the .tt classes for the second .edmx model as well.
Well I just installed EF 4.1 and tried to combine DbContext with a EMDX - When I tried to pass back a view I got the same error - that's why I ended up here... I think the way around this is to separate the functionality out into separate asemblies in the solution...
This can also be resolved by generating the new edmx in visual studio 2010 so it matches the older ones... (And copying over the files it generates)
Using Visual Studio 12, the issue has still not been resolved. As an alternative workaround, I set up the second SQL data model using "old fashioned" Data Classes that pre-date entity models - they're still there and they still work. Use Add - New Item - (Data Category) - LINQ To SQL Classes, open the ServerExplorer, locate the server and database, then drag and drop it onto the data classes pane. Old school - but conveniently overcomes this highly inconvenient issue when the full functionality of entity models is not needed.
I removed the edmx models, removed the Entity package, re-install the entity 5.0 and works.
I was working with some legacy software and was not keen on upgrading EF. For me, the below setting on my newly added .edmx needed to be changed to match the .edmx that already existed in the project. My new one said "T4" and I changed it to "Legacy Object Context". I did have to delete the .tt templates that were generated previously in order to get it to build. Otherwise, the old generated files stay there and the new files are also there, causing "property already defined" errors. Thx to all the answers above that helped me figure this out!
(Properties panel, after clicking in the entity designer)

What do you bind NSArrayController's Managed Object Context to in Xcode 4?

I am trying to build an document-based application for beer reviewing that allows you to enter your notes. I have built the model in Core Data and the view in Interface Builder. Following some Xcode 3-based tutorials, I am told to connect the new NSArrayController to the managedObjectContext of File's Owner. If I try and do this in Xcode 4, a circled exclamation point comes up next to "Model Key Path" in the inspector for the NSArrayController.
I can actually load the .xib file in Interface Builder in Xcode 3, make that connection, and then build it in Xcode 4 and it runs, but every field raises a validation error.
The model has an entity named Scoresheet, which has a property named date, which is an NSDate. But if I link it to the value of an NSDatePicker and try to save it to disk, it says I have "multiple validation errors." How can that be? They are both NSDates, right? Actually, I have the same problem with bindings to everything; none of my UI objects will work with my model.
The only thing I can figure is that there is something going wrong in the connection between the File's Owner and the NSArrayController.
I haven't written any code at this point, because I'm of the understanding I shouldn't have to just to link UI fields and core data. Is it different because I am using a document-based application? (I can't get it to work in a single window app, either.)
An answer of "don't use Core Data" isn't going to be productive; I know I can just fall back on a regular data object. I would like to figure this out in the context of Core Data if possible.
TIA!
(Update: this question seems to be vexing a lot of people. I have consulted the Zarra book on Core Data, the Hillegas book on Cocoa Programming, and two O'Reilly books. They all seem to be based on Xcode 3.)
NSPersistentDocument has it's own managed object context, and you should bind the NSArrayController in your document's xib file to that managed object context.
For example, if your document class is called MyDocument, then Xcode will automatically generate a MyDocument.h / .m / .xib for you. In the .xib, the File's Owner is an instance of your MyDocument class, and you can bind the NSArrayController to this, with the binding File's Owner -> managedObjectContext.
I am running into the same problem (the CarLot example in Chapter 11 of Hillegass, right?)
The following blog entry is from a developer who wrote and maintains an extension for use with NSManagedObjects and considers this a bug in XCode 4 and has filed a report in rdar : http://danieltull.co.uk/blog/2011/04/20/xcode-4-and-creating-nsmanagedobject-subclasses/
I have a machine with XCode 3 on it, I will eventually give up beating on this in 4, create the project in XCode 3 and import it into XCode 4.
Edited to add: Adding the element in XCode 3 and linking the outlet, and then importing the project into XCode 4 works fine, it does seem that this is a bug in XCode 4. I do not get validation problems from XCode 4 doing this.

Can I inspect a Core Data model from Xcode?

Can I inspect a Core Data model from Xcode?
I want to see if the data are correctly stored into the database.
You can use this tool http://christian-kienle.de/CoreDataEditor
You can inspect all datas from your persistent store
There's no direct "show me some data stored at some path I specified somewhere in my code or at runtime that happens to use this model" feature.
If you want to view a file easily in Xcode, you'll need to add the file to your project (don't let it copy into project - just reference it in place) so you can select it in the navigator.
Caveat: This only works for text-based store types (like XML or some custom text-based store type you cooked up). If you use binary or SQLite store types, all you'll see is binary. There's no SQLite database browsing/editing functions in Xcode.
I have not come across a way to check the Core Data Modal directly from Xcode... right now I use "SQlite Database Browser" to check my database... its a good way to check your data in the database.. you can also execute queries on it...
P.S. If you do come across a way to check the Core Data Modal directly from Xcode, please do post it as an answer here...

Resources