Is it possible to use different Realm Models with the same Storyboard?


#1

Good day, Is it possible to use different Realm Models with the same Storyboard and reuse that Storyboard to show the different properties of each Realm Model? Obviously only one at a time. I attached a diagram with the explanation of my question. Is it possible to do that with Realm?


#2

You have big conceptual issues. I will try to help you, but I don’t think that this is the correct place to do that.

The short answer is: yes.

The long answer is that you probably use some kind of architecture - MVC, MVVM or some other. Every architect you made different layers for different things - like in MVC you have MODELS (aka data), VIEWS (aka screen) CONTROLLER (which connects the data to the view)
So, the view doesn’t depend on the model and the model doesn’t depend on the view.
That means that you only need to change the controller to show other properties of the model.


#3

To clarify one item: The text in your image states:

There is a table with one Realm model on each row

That’s not actually possible - a Realm ‘table’ holds one type of object. Obviously you can have multiple objects, but of the same type. This concept also flows to Realm Results objects which are homogenous so if you run a query or pull data from your database, a results object can only contain one type of object.

In your image it appears there are three different types, so those would be stored in three different ‘tables’.

That being said, if you’re planning on labeling your UI elements based on the data retreived from each realm object - that’s no big deal and should be fairly straight forward - it could be done with a single storyboard and view if you like.

In one of our projects, we have a re-usable tableView that can display a list of customers or a list of items. When the view is initialized it knows to either get the customers or items from Realm and then configures the tableView (headers) accordingly. The tableView delegates know which datasource to get it’s data from to populate the tableView.


#4

Sorry I did not explain well, it is not that there is a model in each row of the table but each line calls each respective model previously created, line 1 assigns the model 1 to be used, line 2 assigns the model 2 to be used and line 3 assigns model 3 to be used one at a time in the general StoryBoard for all. I hope I explained it better.


#5

Yes, that explains it better. As I mentioned in my answer there’s no issue reading in data from a Realm table a using it to set up the UI based on which object was read in. Do you have some code that isn’t working or is there another question?