Is it possible to save an array of objects before Realm ? Every time I make changes to an array, it must be saved in Realm.
My current solution is to save an object for an object with for loop . To add / modify objects, calling save() will do the job, but not when I remove the object from it.
class CustomObject: Object { dynamic var name = "" dynamic var id = 0 override static func primaryKey() -> String? { return "id" } } struct RealmDatabase { static var sharedInstance = RealmDatabase() var realm: Realm! let object0 = CustomObject() let object1 = CustomObject() var array = [object0, object1] init() { self.realm = try! Realm() } func save() { for object in self.array { try! self.realm.write { self.realm.add(object, update: true) } } } }
source share