问题
How would you go about passing Realm objects between controllers?
Would you pass just the ID and then fetch the object in the new controller or just pass the whole Realm object?
回答1:
The current best practice is to just fetch again. If you are working off of a background thread, you can pass primary keys to the main thread and fetch with those. It's not that big of a performance issue in the thousand of objects due to how realm handles the loading of objects
回答2:
As far as I can see, the best approach is to pass primary keys, however I couldn't find a way to query for just the primary keys. Looks like you'd have to first query to get objects; map them to primary keys; then pass them to another thread.
回答3:
I would pass the whole object. Because it's way easier than just fetching the element again and also you need less ressource if you just pass the object.
来源:https://stackoverflow.com/questions/28593921/passing-realm-objects-between-viewcontrollers