store data with realm retrieved by backendless same as parse LocalStorage

hey , as you can see on title i want to store the retrieved data using realm , i just want some guidance how am gonna do that ? do i need to store them with a hashmap array ? or i have to store different columns of data into different arrays ? i want to store them without making any mess (efficiently) what is the best way of doing this please guide me, thanks

Hi,

I am currently working on that too. If you just want to store records without relationships it is pretty simple. Just have to change your class to be compliant with Realm and call real.write for each record :

These examples are in Swift. Could be surely better but you’ll get the idea.

import Foundation
import RealmSwift

class Company : Object {
 
 dynamic var objectId : String? = ""
 dynamic var created : NSDate?
 dynamic var updated : NSDate?
 
 
 dynamic var companyName : String? = ""
 dynamic var companyAdd : String? = ""
 
 override class func primaryKey() -> String {
 return "objectId"
 }
}
backendless.data.of(Company.ofClass()).find(
 query,
 response: { ( companies : BackendlessCollection!) -> () in
 let currentPage = companies.getCurrentPage()
 
 for company in currentPage as! [Company] {
 
 try! realm.write({ () -> Void in
 realm.add(company, update: true)
 })
 
 }
 
 print(Realm.Configuration.defaultConfiguration.path!)
 },
 error: { ( fault : Fault!) -> () in
 print("Server reported an error: \(fault)")
 }
 )
 }

It will create a class and fill it in a Realm file.

You can see the print(Realm.Configuration.defaultConfiguration.Path!) to show the path of your Realm file. It will help you to find it and explore it with RealmBrowser to check if your records are properly saved.

If your target is to store some objects with relationships from Backendless, you have to know that Realm doesn’t support arrays in the class definition. I am working on it to find a way.

Hope you’ll get what you need.

Vincent

hey vincent thanks , was confused but your answer make it clear to me and i don’t think so that i need relations, which is good for me :smiley: ,