Wingzero
Wingzero

Reputation: 9754

what's the meaning of Standalone RLMObjects cannot be added to a Realm while they have any observed properties

I am not very clear about the meaning of Standalone RLMObjects cannot be added to a Realm while they have any observed properties meaning

This is stated in @interface RLMObject : RLMObjectBase comment.

I searched the doc, but none specificly explained on this.

Could someone explain it and give some examples of what is allowed and what is not allowed and what's the bad results? Thank in advance.

Upvotes: 2

Views: 71

Answers (1)

TiM
TiM

Reputation: 15991

This is in relation to the feature of Key-Value Observing compliance that was added to Realm relatively recently.

Essentially, instead of manually tracking when a property in a Realm object changes, it's possible to use Apple's KVO mechanism (Introduction to Key-Value Observing Programming Guide) to register for an object to be automatically notified when that property is changed.

That statement above simply refers to the fact that you cannot create a new Realm object, register for KVO on one of its properties, and then subsequently add it to a Realm instance (In that order). In that instance, it's necessary to register for KVO on the Realm object after it has been added to a Realm instance.

More information on how Realm works with KVO can be found here in the documentation.

Hope that helped!

Upvotes: 2

Related Questions