aryaxt
aryaxt

Reputation: 77646

Objective C - Core Data and setting up relationships?

When linking 2 NSManagedObjects in code, is it required to link them both ways as follow?

Or is it enough to link only 1 of them to another?

The problem is that sometimes my first object loses the pointer to the second object, and I'm trying to find out why this is happening.

// Initialize firstObject
// Initialize secondObject
// Objects have 1 to 1 relationship
firstObject.secondObject = secondObject;
secondObject.firstObject = firstObject;

Upvotes: 0

Views: 280

Answers (1)

Chaitanya Gupta
Chaitanya Gupta

Reputation: 4053

If you have linked the relationship both ways in the data model, then you do not need to write both these lines in your code. Just writing firstObject.secondObject = secondObject; should be enough to link it both ways.

Upvotes: 3

Related Questions