Reputation: 988
I have run into an issue in Realm Objective-C v2.4.3 where the collection notification block is not firing for a modification if the modification does not affect the overall query results.
To give a simplified example.
A Feed
object and FeedItem
object. Feed has an items
RLMArray property.
RLMArray<FeedItem *><FeedItem> *items
I have a collection notification block set up for RLMResults where the query is:
[Feed objectsWhere:@"ANY items.status > 0"]
Insertion changes will fire if I modify the status property from 0 -> 1. As would deletions if I had an upper bounds to the query and it moved out of that. However, any changes to a FeedItem's status property that continues to match the query (such as modifying it from 1 -> 2) will not trigger the notification change block as the overall query results are not impacted by this change.
I would've expected this change to fall under a modification as mentioned in the collection docs?
You’re notified about modifications whenever a property of an object has changed, which was previously part of the collection and is still part of it.
You modify the age property of a Dog belonging to that Person.
This makes it possible to discretely control the animations and visual updates made to the content inside your UI, instead of arbitrarily reloading everything each time a notification occurs.
Am I missing something to get this functionality working? The CollectionView's datasource is the RLMResults and I would like to reload an individual CollectionViewCell to reflect the update to the FeedItem's status.
Upvotes: 0
Views: 477
Reputation: 988
In the meantime I have worked around this by adding a lastModified
property to Feed
and then when making a change on FeedItem
I update last modified using the inverse relationship.
self.feed.lastModified = [NSDate date];
Not that great, but it fires a modification change in the collection notification which is what I was after.
Happy to accept another answer that has a better way to achieve this.
Also found two existing Realm github issues which I've commented on
https://github.com/realm/realm-cocoa/issues/4305#issuecomment-283688989
https://github.com/realm/realm-cocoa/issues/3885#issuecomment-283274197
Upvotes: 0