ios - RLMArray<> returns different instances each time -
@realm:
why rlmarray gives different instances of objects @ runtime?
this how defined rlmarray:
@property rlmarray<houseimage> *images;
i add/remove houseimage
objects array time (in transactions).
when i'm accessing images as:
_house.images[indexpath.row]
every time different instances i.e.
(lldb) p _house (rlmaccessor_v0_house *) $52 = 0x00000001701a5780 2015-08-30 23:02:07.695 apt note[5992:1308601] loading image named: 1c178a31-5f33-4cd3-9b7c-b026df7a5e19_2 2015-08-30 23:02:07.731 apt note[5992:1308601] loading image named: cfd99689-12c4-49cb-aab6-850ffcd902d7_3 2015-08-30 23:02:07.750 apt note[5992:1308601] loading image named: 194d55ea-125a-4cfc-8ccf-758e929be7d5_4 // first time when iterating array. [house] object remains same, not images array items. (lldb) p _house (rlmaccessor_v0_house *) $53 = 0x00000001701a5780 (lldb) p _house.images[0] (rlmaccessor_v0_houseimage *) $54 = 0x00000001740bbf60 2015-08-30 23:02:36.947 apt note[5992:1308601] loading image named: 1c178a31-5f33-4cd3-9b7c-b026df7a5e19_2 2015-08-30 23:02:36.986 apt note[5992:1308601] loading image named: cfd99689-12c4-49cb-aab6-850ffcd902d7_3 2015-08-30 23:02:37.031 apt note[5992:1308601] loading image named: 194d55ea-125a-4cfc-8ccf-758e929be7d5_4 // second iteration (lldb) p _house (rlmaccessor_v0_house *) $55 = 0x00000001701a5780 (lldb) p _house.images[0] (rlmaccessor_v0_houseimage *) $56 = 0x00000001740bc140
if see log, house
object remains same. however, instances in rlmarray
(images
) have changed out of nowhere. nobody other piece of code reading/writing realm while happening.
does have idea why happening?
if i'm not clear, please let me know, try explain more clearly.
this expected behavior. in order realize zero-copy storage system, realm not hold actual data @ all. realm swizzles property accessors persisted properties dynamically fetch properties, when access property multiple times, returns different instance each time, design. rlmarray
same as it. each time want access elements of rlmarray, realm returns creating different proxy object.
fyi: if objects not persisted, rlmarray
returns same instances every time. because rlmarray
backed nsarray
https://github.com/realm/realm-cocoa/blob/master/realm/rlmarray.mm#l153-l159.
but once object persisted, rlmarray
changes rlmarraylinkview
. above reasons, rlmarraylinkview
return different instances every time. https://github.com/realm/realm-cocoa/blob/master/realm/rlmarraylinkview.mm#l193-l197
Comments
Post a Comment