1
votes

According to Realm model description I have

Realm data models are defined using traditional NSObject-style classes with @properties. Simply subclass RLMObject to create your Realm data model objects. Apart from the fact that they can be added to a Realm for persistence and sharing between threads, Realm model objects function like any other objective-c objects - you can add your own methods and protocols to them and use them like you would any other object. The only restriction is that objects can be used only on the thread on which they were created.

Can anybody help to explain The only restriction is that objects can be used only on the thread on which they were created.

If I create an instance of RLMObject in background thread, can I use it as a normal object in the main thread? When say normal object, I mean that access or change its properties, use its method ...

Thanks in advance.

1

1 Answers

0
votes

You can create two separate RLMObject instances of the same datapoint, but you cannot share one RLMObject instance across threads. In your case, what you need to do if you create an instance of an RLMObject on a background thread, is fetch the same data again (via a query) in a separate RLMObject instance on the main thread. (We are adding primary keys to make this easier. We are also considering adding a way to share instances across threads but that would come with a constant performance penalty.)