我有这个对象(删除了不相关的属性):
HFAppointment; id: 0xd8ec6f0 <x-coredata://2AA46AB1-11AF-431B-9289-63DEFCDAFED6/HFAppointment/p2> ; data: {
cost = 60;
deleted = 0;
})
连同这段简单的代码:
[appointment setDeleted:[NSNumber numberWithInt:1]];
[appointment setCost:[NSNumber numberWithInt:1]];
问题是运行这段代码后我得到:
HFAppointment; id: 0xd8ec6f0 <x-coredata://2AA46AB1-11AF-431B-9289-63DEFCDAFED6/HFAppointment/p2> ; data: {
cost = 1;
deleted = 0;
})
NSManagedObject
子类如下所示:
标题:
#import <Foundation/Foundation.h>
#import <CoreData/CoreData.h>
@interface HFAppointment : NSManagedObject
@property (nonatomic, retain) NSNumber * cost;
@property (nonatomic, retain) NSNumber * deleted;
@end
实现:
#import "HFAppointment.h"
@implementation HFAppointment
@dynamic cost;
@dynamic deleted;
@end
就是这样,我没有那个类的自定义 setter 或 getter。我在整个项目中搜索了 deleted
的出现,它只用于谓词,没有其他类使用该 setter。
我尝试删除并重新创建 NSManagedObject
子类,但没有成功。我还尝试从模拟器中删除该应用程序并进行了干净的构建,但无济于事。
作为记录,deleted
属性看起来像这样(更改为 Integer 32 和/或删除默认值和/或使用 int32_t
而不是 NSNumber
无效):
有什么想法吗?
最佳答案
经过无数小时的无休止搜索,结果证明解决方案很简单,尽管晦涩难懂。
This article让我发现 deleted
显然是 CoreData 中的保留关键字。只需重命名属性即可解决问题。我找不到这些关键字的列表来支持我的答案,所以如果有人知道这样的列表,请随时发布。
NSPropertyDescription documentation确实提到了 optional
、transient
和 readOnly
,但这就是我能找到的所有内容,而且还不清楚它们不能被使用。
最令人恼火的是,XCode 从未发出任何与此相关的警告,所以这真的是猜测。
关于ios - CoreData : setAttribute has no effect 令人困惑的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19479694/