and this works just fine for a normal tableview with no sections as it just inserts the new cell into section 0.

However, taking a look at the GroupedTableView (tableview with some sections) example they simply add a notification block to the Realm object itself. Which notifies you of any change, not particular insertions/deletions etc.

While this works, it really isn't the best solution since you lose the nice animations provided by iOS for free.

My question is really just, how could I add fine grained notifications to an array of Results

var objectsBySection = [Results<DemoObject>]()

I've thought about looping through the array and adding a notification block to each result object, however since new Result objects can be added to this 2D array, this doesn't seem like a good solution.

Does anyone have experience using Realm with a sectioned tableview that has dynamically growing amount of sections/cells?

~~~~~~~~~~~~~~~~~~~~~~~~~~ UPDATE WITH ANSWER ~~~~~~~~~~~~~~~~~~~~~

So thanks to @bogdanf, I was able to find a solution to this. I am posting my solution here since it is not exactly the same as @bogdanf suggested, but his answer led me to the solution so here it is.

First, in my application sections are not exactly infinite. The user when adding objects adds onto them, but they're limited quantities. I.e I can create an array and append my actual Realm objects to them, thus allowing me to group the objects via their appropriate section.

So thats the first step, I create an array of all my sections, in my app this amounted to ~48 sections, so the runtime won't be too bad when adding notifications.

After creating my array of sections, I query realm for the correct object that corresponds to the sections like so:

The reason I am just simply reloading sections instead of deleting or inserting specific rows, is because this does the same thing, it's more concise and a crucial factor is it allows for the section title/height to be recalculated.

Since I am starting with an array of sections ~48, this would mean that if the user were to start from a new install, their would be 48 empty sections and that looks horrible.

So, in my simplistic approach, it reloads everything only if new sections are added. If you want to benefit from the nice insert animations you could check instead what sections were added, insert them one by one in the table and then add the new objects to them.

Note: My method to check if sections were added is quite intensive, basically it iterates through all the objects in the DB, so you may want to check it with a realistic load in your app. Unfortunately, until Realm would permit distinct or group by queries this is the only way I could imagine to solve this issue.