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
2
votes
3 answers

casting object of type id to to an unknown type at runtime

I have a method that takes as a string the name of an entity in my sqlite database that I am trying to streamline to use as little repeating code as possible. here I have entity as id that I am trying to set to the require object type in readiness…
user7865437
  • 812
  • 14
  • 28
2
votes
1 answer

reason: 'An NSManagedObject of class 'NSManagedObject' must have a valid NSEntityDescription?

I am getting error in core data x code8.3, Data base is added DB. Error is..... Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'An NSManagedObject of class 'NSManagedObject' must have a valid…
2
votes
1 answer

Cocoa pod with Core Data can not find entity in consuming app

I've created a framework that's a cocoapod, the framework uses core data, my pod spec has: s.resource_bundles = { 'FrameworkModel' => ['Model/**/*.xcdatamodeld'] } and everything works fine in a demo app that's a different target in the…
Fred Faust
  • 6,696
  • 4
  • 32
  • 55
2
votes
2 answers

NSEntityDescription returns nil on iPad Air 7.1 only

I have been working with CoreData recently for an app of mine. Oddly enough it is crashing only on the iPad Air with iOS 7.x. I have run in both on physical devices and the iOS simulator, it never fails to crash on the Air, and always runs…
chaoscope
  • 33
  • 2
2
votes
1 answer

iOS: core data update object with one- with to-many relationship

In my app I have this code to update a DB: NSManagedObjectContext *context = [self managedObjectContext]; NSFetchRequest *fetchRequest=[NSFetchRequest fetchRequestWithEntityName:@"Struct"]; NSError *error = nil; for (id element in…
cyclingIsBetter
  • 17,447
  • 50
  • 156
  • 241
1
vote
1 answer

iOS - edit database entry using NSEntityDescription and NSManagedObjectContext

I am an iOS newbie. I am using the following function to insert new rows to my database - -(void)insertMetricAction:(NSString *)action andValue:(NSString *)value andStatus:(NSString *)status { MetricDb *aDbMessage = (MetricDb *)[NSEntityDescription…
Suchi
  • 9,989
  • 23
  • 68
  • 112
1
vote
0 answers

NSEntityDescription name Optional

I have an instance of NSEntityDescription that I obtained through the entity() method on the class of an NSManagedObject subclass. I want to get its name, but the type of that property is String? rather than just String let entityName: String =…
Michael Hulet
  • 3,253
  • 1
  • 16
  • 33
1
vote
0 answers

Creating a framework where I need to provide developers with a super entity for their core data entities

I am creating a framework the utilized Core Data. I have an Entity that I will need developers to specify as the parent entity of entities they make within their app when they want to utilize the framework. What is the best way to allow developers…
1
vote
0 answers

Swift4 Core Data how to insert into NSOrderedSet by date?

I have a core data model with one record having a to many relationship to photos entity. The relationship is flagged as ordered in the data model. The code below adds a new record at the last index. I want records to be ordered by date - meaning I…
Alex Stone
  • 46,408
  • 55
  • 231
  • 407
1
vote
1 answer

Task of NSManagedObject, NSManagedObjectContext, NSEntityDescription, NSPredicate, NSPersistentStoreCoordinator

i am new in ios field, read the tutorial related to above class from apple official website. But i can't understand what is actually job of the NSManagedObject, NSManagedObjectContext, NSEntityDescription, NSPredicate given class. so please help…
1
vote
1 answer

Finding the entities of a CoreData model at runtime

I have an macOS app being developed in Xcode (8.3.2) in SWIFT. I have a CoreData model with a number of entities and an identifier (myidentifier). I want to be able to identify the entities of the model programatically at runtime so that I can…
1
vote
1 answer

Incompatible pointer types initializing 'NSEntityDescription *' with an expression of type '__kindof NSManagedObject * _Nonnull'

every thing works fine but i get this notice and try to search to find solution but with no luck AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication]delegate]; NSManagedObjectContext *context =…
Bosoud
  • 158
  • 4
  • 24
1
vote
1 answer

replacing attribute within CoreData

I have an entity within CoreDate called BudgetDetail. I have the below code which i want to update the attribute 'remaining' however it seems to be adding a new record rather than updating. func checksBudgetDetail(budgetName: String, spendAmount:…
Jess Murray
  • 1,273
  • 1
  • 10
  • 32
1
vote
1 answer

Core Data NSEntityDescription.entityForName returns nil, but managedObjectModel.entities lists the entities

I'm trying to create a subclass of NSManagedObject in swift. I have created two entities called Pages and Book in the model editor and generated their class files. Here are the two classes: @objc(Pages) class Pages: NSManagedObject { …
user2732722
  • 615
  • 1
  • 10
  • 22
1
vote
1 answer

Programmatically check if Core Data entities are indexed

I am currently working with a library that sits between Core Data and the sqlite database (i.e. it handles a lot of the Core Data calls, and translates them into SQL queries). I have noticed that when creating the sqlite tables, it doesn't add any…