Questions tagged [nsmanagedobject]

NSManagedObject is a generic class that implements all the basic behavior required of a Core Data model object. NSManagedObject is available in OS X v10.4 and later and available in iOS 3.0 and later.

From the documentation:

Overview

A managed object is associated with an entity description (NSEntityDescription) that provides metadata about the object, including the name of the entity that the object represents and the names of its attributes and relationships. A managed object is also associated with a managed object context that tracks changes to the object graph.

[...]

Data Storage

In some respects, an NSManagedObject acts like a dictionary—it’s a generic container object that provides efficient storage for the properties defined by its associated NSEntityDescription instance. NSManagedObject supports a range of common types for attribute values, including string, date, and number (see NSAttributeDescription for full details).

Resource

Sample NSManagedObject declaration

In Objective-C:

NSManagedObjectContext *context = [self managedObjectContext];

//create a new managed object
NSManagedObject *newFlight = [NSEntityDescription insertNewObjectForEntityForName:@"FlightEvent" 
        inManagedObjectContext:context];

In Swift:

let newFlight = NSEntityDescription.insertNewObjectForEntityForName("FlightEvent", inManagedObjectContext: managedObjectContext)
1597 questions
18
votes
3 answers

Storing NSManagedObject in a dictionary (NSDictionary)

I have a custom class, which is a subclass of NSManagedObject. I would like to store it in a dictionary, but when trying to do so I receive a Property list invalid for format: 200 error. Here is how I try to create the dictionary: NSDictionary…
antalkerekes
  • 2,128
  • 1
  • 20
  • 36
17
votes
2 answers

NSManagedObject can't get attributes from NSAtomicStoreCacheNode

I have one-to-one relationship between entity A and entity B (one sided), for example named bRel. I have subclasses of NSAtomicStore (MyStore) and NSAtomicStoreCacheNode (MyCacheNode). In the load: method of MyStore I create instances of MyCacheNode…
16
votes
2 answers

Core Data - Iterating through the attributes of a NSManagedObject

I am a noob at core data, so here goes. I have a core data object, for example student. The student has mane attributes, like name, age, dob, address, and so on. Now I need to display all these attributes into a table view. Is there any easy way to…
stephen
  • 1,617
  • 3
  • 20
  • 27
16
votes
2 answers

Obtaining entity name from NSMangedObject subclass class object

Is there a bulit-in way to obtain an entity name from the class object of an NSManagedObjectSubclass? I know that this can be readily determined from an instance of a subclass, but I want to ask the class itself. I can write a class function, but…
pickwick
  • 3,134
  • 22
  • 30
16
votes
1 answer

Abstract entities and inheritance in Core Data

I have a data model for Formula 1 races with 3 entities: RacingActor: Abstract entity Pilot: inherits from RacingActor Team: inherits from RacingActor If I generate NSManagedObject subclasses to represent these entities, the code generated…
cfischer
  • 24,452
  • 37
  • 131
  • 214
16
votes
5 answers

Difference Between NSManagedObject, NSManagedObjectContext and NSManagedObjectModel

What is difference between these three classes [NSManagedObject , NSManagedObjectContext , NSManagedObjectModel ] of core-data and how can we describe in easiest Way?
iMash
  • 1,178
  • 1
  • 12
  • 33
15
votes
4 answers

Add new attribute to existing Core Data Entity Relationship

I'm not sure if my understanding of Core Data relationships is flawed as I can't seem to achieve what I want to do. I have a 2 entities created to manage Chat on the app and a one-to-Many relationship between the users and the messages. So a user…
15
votes
2 answers

Sort CoreData results using NSPredicate in Swift

I'm currently writing a simple phone book app in Swift and need to sort the results from a CoreData query. Basically, I set up an NSManagedObject called "Directory", with the appropriate field names in - e.g. "name_f" is the user's name. The names…
Oliver Spencer
  • 2,021
  • 3
  • 16
  • 22
14
votes
1 answer

Why exactly would one subclass NSManagedObject?

I've read many of the SO questions on NSManagedObject, the Apple docs, and more, but I still don't really get what subclassing NSManagedObject is for - what role does it play? In the Apple docs it talks about how I can't override a bunch of…
Vervious
  • 5,559
  • 3
  • 38
  • 57
13
votes
6 answers

Xcode4: Different code generated for custom core data managed objects

Now that Xcode4 is publicly available I'm moving this question out of Apple's secret dev forum: Can someone explain why the code generated in the following procedure is different than in Xcode3? Is the code better or might this be a bug? I use Core…
pokstad
  • 3,411
  • 3
  • 30
  • 39
13
votes
1 answer

Debugging SIGABRT within NSManagedObjectContext -save:

From inside NSManagedObjectContext -save: I am getting this message: Assertion failed: (_Unwind_SjLj_Resume() can't return), function _Unwind_SjLj_Resume, file /SourceCache/libunwind/libunwind-24.1/src/Unwind-sjlj.c, line 326. Program received…
westsider
  • 4,967
  • 5
  • 36
  • 51
13
votes
4 answers

CoreData: error: Serious application error. Exception was caught during Core Data change processing

I am running into major issues developing my iphone app. here is the full error: CoreData: error: Serious application error. Exception was caught during Core Data change processing. This is usually a bug within an observer of…
Ox Smith
  • 509
  • 1
  • 7
  • 20
13
votes
2 answers

How to get all records From CoreData Base using NSManagedObjectSubClass?

I am trying to implement CoreData in ios Application,Now I want to Fetch all records from Entity MUSTHAFA My NSManagedObjectedSubClass is MUSTAHFA MUSTHAFA.m #import #import @interface MUSTHAFA :…
12
votes
1 answer

CoreData error driving me crazy... CoreData: Serious application error. An exception caught from delegate of NSFetchedResultsController

My application has two tab bars... Each takes the user to a tableviewcontroller that presents him with a list of items. The first view lets the user record entries in the database. The other tab/view reads from the database and presents those…
12
votes
1 answer

What are the functional differences between Coredata's CodeGen 'manual/none + create NSManagedObject subclass' vs. 'category/extension'

I've read Subclassing NSManagedObject with swift 3 and Xcode 8 beta and read this great tutorial. Still have questions on some points. The similarities are: I can customize both classes however I like. I can add new attributes or remove or rename…
mfaani
  • 33,269
  • 19
  • 164
  • 293