Passing Realm objects between ViewControllers

别来无恙 提交于 2019-12-25 04:28:08

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!