Realm: Advantage using List [iOS][Swift]
Using Realm makes our code clean and easy to communicate with local database. Realm includes List class which is quite powerful. I did use it but didn’t know the actual power of it until today. Before diving onto it, let me show you 2 ways creating array if you are using Realm.
// Realm list approach let students = List<Student>() or // Swift standard array approach let students = [Student]()
Swift Standard Array Approach
Using second approach, you will be able to create array of student. But every time you access students variable, you will get exactly the same value you have stored. The value will be changed only once you change it.
Realm List Approach
Using realm list, you create array like swift standard approach but the result is quite different. While using List approach, realm will get all updated List of Student. However, in standard approach, you will get only those list of students which was assigned to students variable initially. So, the basic idea is, you will get constant list of students all the time if you use swift Standard Approach and you will get dynamic list of students all the time if you go with Realm List Approach.
Note while using List approach
Make sure you are fetching List from local database. It won’t work if you are just creating class and playing with object. You will need to create Realm class and need to store datas in local database first. And only you will get result as I have mentioned.
Note this was helpful. If so, don’t forget to share and like this post.