1

I have a weak property:

@property (nonatomic,weak) NSManagedObjectID *locatedMessageID;

App will crash when calling -(void)setLocatedMessageId. The error is:

EXC_BAD_INSTRUCTION(code=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?

hypercrypt
  • 15,389
  • 6
  • 48
  • 59
Zhang Jiuzhou
  • 759
  • 8
  • 22

1 Answers1

-1

NSManagedObjectID is not advisable. 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.

Contrary to the comment below, you are better off with the object itself.

Mundi
  • 79,884
  • 17
  • 117
  • 140
  • 3
    Actually, do the opposite. A managed object is a collection of references to things in the context, identified by the managed object id - this is why using the object ID is often preferable to using the managed object. – quellish Oct 23 '14 at 02:09