Kodeco Forums

Video Tutorial: Beginning Realm on iOS Part 4: Collections

This video covers a couple of Realm's dynamic collections - Results and List.


This is a companion discussion topic for the original entry at https://www.raywenderlich.com/3479-beginning-realm-on-ios/lessons/5

I found this interesting in that you decide to relate the one to many relationship using a List. Whenever I have done this in Realm, I have created a dynamic variable in the parent ‘Child’ table that points to the key in the "parent’ table. So for example, I would have added this to the Task object

dynamic var user:User!

Then when creating a new task, I would just add the current or selected user to that task rather than the other way around.

I believe that this is more in keeping with a relational database model and that is where I am coming from.
I have to get my head around the way that you are doing it as it seems backwards to me.

However, I have to say that the series is absolutely excellent overall. I learned how to use Realm more or less piecemeal and had this series been available a few months ago, it would have saved me a lot of time. Thanks for doing this.

Hey! Absolutely agree with you - this is the type of relationships that one builds when they have a lot of experience with relational databases. Adding a List doesn’t cost much since the list contains only pointers to the objects (and not copies to the objects themselves) but it preserves the order of the objects, which might be something you are looking for. Imagine how faster it is to just read objects one after the other from a pre-ordered List vs. sorting few thousand objects, which your Messages link to. And you can have few different Lists if you need them, and even re-order them at times (if you so need). Glad you like the videos :+1:

Hello Marin,
Thank you for these great tutorials.
I have a question : What If I would like to make a collection view (or table view) with an array of different type of realm object ? How can I do that ? So in my collection view data source delegate method : cellForItemAtIndexPath I will check the type and I will create a cell according to object type.

Hey Martin, again realm is awesome.

Around 6:00. I think getTask should take an optional bool, it would be more swiftly :p.

Cheers and thanks for the videos.

Hello. Thanks again for your help. I have a question about linkingObjects, if we use this for inverse relationships, will we get a strong reference cycle? Does realm take care of this?

Hi Andy, linking objects is a dynamic property, much like a results objects - it doesn’t retain any objects, don’t worry.