nsmanagedobject

NSManagedObject and KVO vs Documentation

六眼飞鱼酱① 提交于 2019-12-03 01:29:28
I have a custom NSManagedObject subclass, say, Person . I also have a UIView registered with -addObserver:forKeyPath:options:context: to observe various properties of a Person , some of which are persistent like "name" and others are just dumb KVO-compliant accessors unrelated to Core Data, like "drinking". @interface Person : NSManagedObject { BOOL drinking; } @property (nonatomic, retain) NSString* name; @property (nonatomic, readonly) BOOL drinking; @end @implementation Person @dynamic name; ... - (void) getDrunk { [self willChangeValueForKey: @"drinking"]; drinking = YES; [self

Invalid redeclaration on CoreData classes

时光毁灭记忆、已成空白 提交于 2019-12-03 01:10:19
问题 I am working with CoreData, on an entity called "RoleName". The problem is: I click on "Create NSManagedObject subclass" from within my model, and so it automatically creates the classes for my entity. However, on the declaration of the class, I get this error: Invalid redeclaration of "RoleName" even though I don't have any other class with the same name. 回答1: This is because Xcode handles all that by itself. I felt it like a bit of trouble as the auto generated classes don't have all my

“[something copyWithZone:]: unrecognized selector sent to instance” when using Bindings / Core Data

余生长醉 提交于 2019-12-02 21:10:18
(self asking and self-answering because I spent hours on the web looking for this, and most of the resources all say "I solved it in the end" without giving an explanation) I had a very simple Core Data + Bindings application: An NSArrayController pulling items out of Core Data An NSTableView rendering them Another NSTableView that when you click on a row in the first table, displays the details of that item Item 3 above was causing application crash, with the error: [(my NSManagedObject) copyWithZone:]: unrecognized selector sent to instance Implementing that method (!) and putting a

Storing NSManagedObject in a dictionary (NSDictionary)

为君一笑 提交于 2019-12-02 18:41:27
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 *dictionary = [NSDictionary dictionaryWithObject: voiceMemo forKey:@"voiceMemo"]; Same result when trying NSDictionary *dictionary = [NSDictionary dictionaryWithObject: (NSData *) voiceMemo forKey:@"voiceMemo"]; It works, however, when trying to save the individual attributes separately: NSDictionary *dictionary = [NSDictionary dictionaryWithObject:

CoreData could not fulfill a fault for

£可爱£侵袭症+ 提交于 2019-12-02 15:48:14
I have a really annoying problem, which I just can't seem to get fixed. I have a view when I send a message that gets saved to the Core Data, when thats done it asked the database for a random message (sentence) and saved that as well to an other row in the database. If I do the last part hardcoded, without fetching data from the DB, it works all fine and dandy, but as soon as I fetch the random row from the DB it goes crazy. In my AppDelegate.m: - (void)save { NSAssert(self.context != nil, @"Not initialized"); NSError *error = nil; BOOL failed = [self.context hasChanges] && ![self.context

Invalid redeclaration on CoreData classes

怎甘沉沦 提交于 2019-12-02 14:39:05
I am working with CoreData, on an entity called "RoleName". The problem is: I click on "Create NSManagedObject subclass" from within my model, and so it automatically creates the classes for my entity. However, on the declaration of the class, I get this error: Invalid redeclaration of "RoleName" even though I don't have any other class with the same name. This is because Xcode handles all that by itself. I felt it like a bit of trouble as the auto generated classes don't have all my properties. So follow these steps to get this as it used to be: Delete what ever classes you already made for

How to list variables for NSManagedObject

て烟熏妆下的殇ゞ 提交于 2019-12-02 12:26:28
问题 I needs to list variables for NSManagedObject, I know there is a way to do it using "class_copyIvarList" as given in How do I list all fields of an object in Objective-C? but "class_copyIvarList" isn't working on "NSManagedObject". here is piece of code Im using, which is working perfectly fine for "NSObject" but not for "NSManagedObject": unsigned int outCount; Ivar *vars = class_copyIvarList([self class], &outCount); for (int i = 0; i < outCount; i++) { Ivar var = vars[i]; unsigned int

Failed to call Designated Initializer on NSManagedObject Class — CoreData

…衆ロ難τιáo~ 提交于 2019-12-02 10:11:39
I have really been stuck on this issue and I have referred to this stackoverflow post but my application still crashes with the issue: Failed to call Designated Initializer on NSManagedObject Class So, I have multiple entities and I have subclassed the NSManagedObject . Let's pretend I have entities named: FirstEntity, SecondEntity, ThirdEntity, Fourth Entity, FifthEntity. Let's also pretend I have two attributes named firstAttribute, secondAttribute in each Entity. I went into the xcdatamold opened up the editor and then selected create NSManagedObject Subclass for all of my entities. Then I

How to update an NSManagedObject whenever a specific attribute is changed?

痞子三分冷 提交于 2019-12-02 07:11:26
问题 Imagine I have a Core Data object, Product. Each Product has a quantity , price , and total attribute. Total is there for efficiency when retrieving items from the table. (I understand that there may be an efficient way to get the computed value using fetched properties, but this is only an example, and that answer is not what I am looking for.) +------+----------+-------+-------+ | Name | Quantity | Price | Total | +------+----------+-------+-------+ | Foo | 1 | 20 | 20 | | Bar | 0 | 30 | 0

Cannot specialize non-generic type 'Set'

独自空忆成欢 提交于 2019-12-02 06:42:54
This is my NSManagedObject : @objc(Order) class Order: NSManagedObject { @NSManaged var orderItems: Set<OrderItem> //error: Cannot specialize non-generic type 'Set' } Anyone know why it doesnt work? OrderItem file is created and works however for following declaration: @NSManaged var orderItem: OrderItem Just for reference if someone should come to this question in the future for this nasty bug, since the discussion went on in the comments. Yes, the default Set type in Swift is generic, but in this case a custom non-generic Set class was shadowing the class defined by the language's standard