[英]ios: why NSManagedObjectID object cannot be weak reference?
I have a weak property: 我的财产薄弱:
@property (nonatomic,weak) NSManagedObjectID *locatedMessageID;
App will crash when calling -(void)setLocatedMessageId
. 调用-(void)setLocatedMessageId
时,应用程序将崩溃。 The error is: 错误是:
EXC_BAD_INSTRUCTION(code=EXC_I386_INVOP). EXC_BAD_INSTRUCTION(代码= EXC_I386_INVOP)。
To solve this problem, only replace 'weak' keyword to 'assign'. 要解决此问题,只需将“弱”关键字替换为“分配”即可。
@property (nonatomic,assign) NSManagedObjectID *locatedMessageID;
But is it safe? 但是安全吗? Why I cannot use weak property here? 为什么我不能在这里使用弱资产?
NSManagedObjectID
is not advisable. 不建议使用NSManagedObjectID
。 Use the object itself instead. 改用对象本身。 You have convenient access to all associated objects and attributes - there is really no need to explicitly fetch the object again based on the object ID. 您可以方便地访问所有关联的对象和属性-确实不需要根据对象ID再次显式提取对象。
Contrary to the comment below, you are better off with the object itself. 与下面的评论相反,您最好使用对象本身。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.