我将 CoreData 与一个实体和该实体的两个属性一起使用。
实体:Binder
属性:名称,lastOpened
,br> 我可以毫无问题地插入实体的新对象,我也可以设置它的名称,但我不能设置它的 lastOpened 属性。
这是我的代码:
Binder *newBinder = [NSEntityDescription insertNewObjectForEntityForName:@"Binder" inManagedObjectContext:context];
[newBinder setName:@"Binder"];
[newBinder setLastOpened:[NSDate date]]; //Tried this first
newBinder.lastOpened = [NSDate date]; //No compiler warning either
但是,当我运行应用程序时,我得到一个错误,-[Binder setLastOpened:]: unrecognized selector sent to instance 0x9688870
我可以验证显示的内存地址实际上是正确的 Binder 对象。关于为什么我可以设置一个属性但不能设置另一个属性的任何想法?谢谢。
活页夹.h:
#import <Foundation/Foundation.h>
#import <CoreData/CoreData.h>
@class Cards;
@interface Binder : NSManagedObject
@property (nonatomic, retain) NSString * name;
@property (nonatomic, retain) NSDate * lastOpened;
@property (nonatomic, retain) NSSet *cards;
@end
@interface Binder (CoreDataGeneratedAccessors)
- (void)addCardsObject:(Cards *)value;
- (void)removeCardsObject:(Cards *)value;
- (void)addCards:(NSSet *)values;
- (void)removeCards:(NSSet *)values;
@end
活页夹.m:
#import "Binder.h"
#import "Cards.h"
@implementation Binder
@dynamic name;
@dynamic lastOpened;
@dynamic cards;
@end