Questions tagged [nsentitydescription]

An NSEntityDescription object describes an entity in Apple Core Data framework. It is available in OS X v10.4 and later and available in iOS 3.0 and later. Its objects are primarily used by the Apple Core Data Framework for mapping entries in the persistent store to managed objects in the application.

An NSEntityDescription object is associated with a specific class whose instances are used to represent entries in a persistent store in applications using the Core Data Framework. Minimally, an entity description should have:

  • A name
  • The name of a managed object class (If an entity has no managed object class name, it defaults to NSManagedObject.)

NSEntityDescription class reference Source Using Entity Descriptions in Dictionaries

NSEntityDescription’s copy method returns an entity such that

[[entity copy] isEqual:entity] == NO

NSEntityDescription supports the NSFastEnumeration protocol. You can use this to enumerate over an entity’s properties, as illustrated in the following example:

 NSEntityDescription *anEntity = ...;
  for (NSPropertyDescription *property in anEntity) {
   // property is each instance of NSPropertyDescription in anEntity in turn
 }


   NSManagedObjectContext *context = <#Get the context#>;

   NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
   NSEntityDescription *entity = [NSEntityDescription entityForName:@"  <#Entity name#>"
inManagedObjectContext:context];
  [fetchRequest setEntity:entity];

   NSError *error;
   NSArray *fetchedObjects = [context executeFetchRequest:fetchRequest error:&error];
   if (fetchedObjects == nil) {
     // Handle the error.
    }
74 questions
12
votes
1 answer

Adding relationships in NSManagedObjectModel to programmatically created NSEntityDescription

When you write a static library which uses CoreData there's a big mess including a normal .xdatamodeld file into the project because you simply cannot just link its compiled version (.momd) into your binary, so it's better to create the whole…
11
votes
4 answers

How to insert new data to entity in Swift?

In Swift previously, I was able to use a code like this to add new data to my "TestEntity" in my data model. NSManagedObject was created for my "TestEntity" and I was able to set its attributes with the "dot" syntax At the end, I would save the…
7
votes
2 answers

Core Data NSPredicate filter by entity class?

How would I create an NSPredicate to filter by entity of class Contact? The solution to NSPredicate check for kind of object class crashes: [NSPredicate predicateWithFormat:@"person.class == %@", [Contact class]]; *** Terminating app due to…
ma11hew28
  • 121,420
  • 116
  • 450
  • 651
5
votes
1 answer

Why are NSManagedObject and NSEntityDescription separate classes?

It seems that an NSEntityDescription object describes data and an NSManagedObject object contains the corresponding data. If you have a normal NSObject subclass, the description of the data and the actual data are in the same place, aren't they.…
nevan king
  • 112,709
  • 45
  • 203
  • 241
4
votes
3 answers

Check if NSEntityDescription key exists

I need to check if an NSEntityDescription key exists before trying to set the value. I have a dictionary of data from JSON and don't want to try setting keys that do not exist in my object. Appointment *appointmentObject = [NSEntityDescription…
Bot
  • 11,868
  • 11
  • 75
  • 131
4
votes
2 answers

NSFetchedResultsController multiple entities for UITableView

I have two entities one called Post and one called User. Post<<---->User is the relationship in core data. I am using a NSFetchedResultsController to fetch all Post records in my core data stack and then displaying them in a UITableView. Each…
3
votes
1 answer

Incompatible pointer types assigning to 'NSManagedObject Subclass*' from 'NSEntityDescription *'

I'm saving the Managed Object Context, and am using the following to do it: trainingDayObject = [NSEntityDescription entityForName:@"trainingDay" inManagedObjectContext:self.context]; It works, everything seems great, but I'm getting the…
Arel
  • 3,888
  • 6
  • 37
  • 91
3
votes
2 answers

Magical Records how to create just one unique entity

I get some object from the server it is an json string. I want to create entity using keys and values from this string. So I use this method for create entity using Magical Records Entity *entity = [Entity createEntity]; I have id for each entity,…
Matrosov Oleksandr
  • 25,505
  • 44
  • 151
  • 277
3
votes
2 answers

How to check if a relationship has been established - Core Data

How would you check if a relationship has been established when adding data to core data? Currently I have a TO MANY relationship between two of my entities. I am attempting to create a detail view but am struggling and i'm not sure if its due to a…
Sgillon
  • 147
  • 12
3
votes
2 answers

Is it possible to have multiple core data "databases" on one iOS app?

I'm wanting to write a "management" game that utilizes Core data heavily. The game requires a pre-set, pre-defined dataset that cannot be changed by the user/system; it is used to seed the game with data and is meant to be read-only. The best…
3
votes
2 answers

iOS - How to create a login process using keychain / Core Data?

I am creating a multi-user iPhone app, and I am trying to finish up the coding for the user login in process. I can successfully create an account, and store the data the user inputs into the Core Data DB, and the pin (password) into the Keychain,…
ipatch
  • 3,933
  • 8
  • 60
  • 99
2
votes
1 answer

NSManagedObjectModel mergedModelFromBundles error

I'm working with Core Data and having a lot of trouble's getting data into the database right off the start of my app. Below is some of the code I've grabbed from a tutorial I followed. The point where I get the SIGABRT is outlined below. Any…
2
votes
1 answer

How to get NSAttributeDescription?

I have a User : NSManagedObject. What's the best way to get an NSAttributeDescription of it's userID attribute?
2
votes
2 answers

Using Core Data to fetch generates 'unrecognized selector error'?

I'm trying to retrieve a list of objects saved using Core Data. No changes where made to the default setup made by Xcode when creating the project. There are items in the actual data store, and the entity Transaction works fine when saving but when…
2
votes
1 answer

Checking for duplicate in sqlite before inserting them (Core data)

i'm inserting new objects into the database by core data. Is there any way to check if there is any duplicate in the database before i insert the values in? for (int i =0;i<[categoryArray count];i++) { Category * cat = [categoryArray…
Steve Jabs
  • 209
  • 5
  • 21
1
2 3 4 5