我有一个通常在xcdadmodeld中定义的类。对此类型的版本控制是PITA,所以当我想添加一些更小的变量时,我只需添加它们;第一行已经存在并在模型中定义,第二行不在模型中:
@property (nonatomic) float latitudeNorth; //this is a sample, there are more
@property (nonatomic) float latitudeNorthEast;
在.m中,我有:
@dynamic latitudeNorth;
@dynamic latitudeNorthEast;
我也尝试过:
@dynamic latitudeNorth;
@synthesize latitudeNorthEast;
我从JSON字符串中将值加载到这些浮点数中......
self.latitudeNorth = [inDictionary[@"latitude_north"] floatValue];
self.latitudeNorthEast = [inDictionary[@"latitude_1"] floatValue];
如果我检查这些值,它们是正确的。后来我回去研究这些价值......
if (inLatitude > self.latitudeNorth) return false;
coords[0] = CLLocationCoordinate2DMake(self.latitudeNorthEast, self.longitudeNorthEast);
当我查看调试器中的值时,self.latitudeNorth具有正确的值,self.latitudeNorthEast为零。
出现实例已失去其不属于模型的ivars的值。但是,我的印象很好。我想我错过了其他的东西 - 也许是一个直接的宣言?
答案 0 :(得分:0)
如果您的属性不是Core Data模型中的属性,则当对象变为故障时,该值可能会被清除。之后,Core Data可以从商店中再次获取对象,但之后您的属性为空,因为它不属于属性集。
答案 1 :(得分:0)
为什么要使用dynamic。如果你编写动态属性,那么你必须为属性编写setter和getter方法。我认为如果你没有定义你的getter和setter属性编译器会导致崩溃或者会出错并且不会编译。