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
0
votes
0 answers

Can I add a protocol to a Mogenerator-generated class file

I'm using Mogenerator to generate my class files in my iPhone app. I have a Staff base model which I want to extend using different protocols eg. protocols like manager, security etc but a staff member may be entitled to both manager and security…
Gerard
  • 4,818
  • 5
  • 51
  • 80
0
votes
2 answers

confusion with implementing core data

I am a beginner and I am trying to move my app to Core Data. I am following the Big Nerd Ranch 3rd Edition book, but in that book they have a store class that holds all its items in an item class. My app is different. I have an task class and the…
EvilAegis
  • 733
  • 1
  • 9
  • 18
0
votes
1 answer

Possible to set multiple parent entities for Core Data NSManagedObject?

I have created the following example Core Data NSManagedObject subclasses: PBCommentableObject : NSManagedObject // to allow comments on object @property (nonatomic, retain) NSSet *pBcomments; // unordered set of PBComment objects PBComment :…
Ken M. Haggerty
  • 24,902
  • 5
  • 28
  • 37
0
votes
1 answer

Get the MappingResult firstObject value within the Persistent Storage to avoid "Illegal attempt to establish relationships" errors

I am fetching an object from the persistentStoreManagedObjectContext and showing some of its value to my user within a UIView. That object, let's call it Book has an Author relationship. Whenever I am about to display that book, I check if the…
0
votes
1 answer

is there a way to see which objects in a managedobjectcontext have not yet been added to the persistent store?

is there a simple and efficient/fast way to query a managedobjectcontext to get an array of all the managedobjects in the context that have not yet been added to the persistent store? i ask this because i would like to be able to save…
0
votes
1 answer

adding a Core Data object from a segue

in getting familiar with core data i have found myself puzzled by the question of what to pass various view controllers (VCs) when trying to add data. for example, in the CoreDataRecipes project that apple provides as an example…
dave adelson
  • 853
  • 9
  • 15
0
votes
1 answer

Core Data: Relationship without destination entity?

Is it possible to create a relationship without specifying a specific custom NSManagedObject as the destination entity? E.g., I would like to create an NSManagedObject subclass called SyncInfo that will contain attributes regarding syncing and sync…
0
votes
1 answer

NSManagedObjectContextDidSaveNotification with numerous core data stores

I have 2 separate data stores in my app, both of which go onto a background thread at the same time. I therefore have this code to set it up: NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter]; [notificationCenter…
Andrew
  • 15,935
  • 28
  • 121
  • 203
0
votes
2 answers

iOS Apptentive SDK - NSInvalidArgumentException from `[NSManagedObject setup]`

i'm new in iOS programminng. I want to use feedback system with Apptentive SDK in my first App. There is no errors while compiling, but when it start to make connection with Apptentive server, i get this error message: 2013-07-11 15:32:19.438…
Adam Kaczmarek
  • 146
  • 2
  • 10
0
votes
1 answer

How to pass NSManagedObject into ECSliding

I don't know if anyone has asked this question or perhaps I have overlooked. Please accept my apologies. I have a LoginViewController in front of InitialSlidingView. How can I pass NSManagedObjectContext into InitialSlidingView and subsequently to…
Adrian Hoe
  • 2,081
  • 2
  • 12
  • 12
0
votes
1 answer

Adding attribute value to core data IF value already exists

I have to say that everyone on the forum has been really helpful with my attempts at learning core data. I am adding attribute values to my core data entities and creating a relationship when the user selects a row as shown below: -…
Sgillon
  • 147
  • 12
0
votes
1 answer

Xcode: @dynamic class variable not working

I have a class which declares a User and includes these variables: (User.h file): @property (nonatomic, retain) NSString * name; @property (nonatomic, retain) NSString * unid; (User.m file): @dynamic name; @dynamic unid; I have an array of values…
carloabelli
  • 4,289
  • 3
  • 43
  • 70
0
votes
1 answer

CoreData updating an NSManagedObject more than once saves several copies?

I have 90 CoreData entities called "ItemModel" with 2 attributes 'uid', 'description', where each of the item is inserted as an NSManagedObject: NSManagedObject *object = [NSEntityDescription insertNewObjectForEntityForName: @"ItemModel"…
chongsj
  • 25
  • 1
  • 6
0
votes
1 answer

Core Data, deleting a managed object's effect on the objects "superView"

I have a managed object that is in a "to-many" relationship to other sub managed objects. When I delete one of the sub managed objects, the array on the main managed object that represents the relationship to the sub managed objects is emptied.…
OWolf
  • 5,012
  • 15
  • 58
  • 93
0
votes
1 answer

Change default values for certain attributes for future NSManagedObject insertions?

How could I go about doing this programmatically? Subclass NSManagedObject and override -(void)awakeFromInsert;? Then I suppose set the attribute values in the methods implementation?
Skyler
  • 2,834
  • 5
  • 22
  • 34