Saving Array to Realm in Swift? -


is possible save array of objects realm? anytime make change array should saved realm.

my current solution save object object for loop. append/modifying objects calling save() job, not when remove object 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() {          object in self.array {             try! self.realm.write {                 self.realm.add(object, update: true)             }         }     }  } 

to save lists of objects have use realm list, not swift array.

let objects = list<customobject>() 

then, can add elements:

objects.append(object1) 

take @ to many relationships , collections sections of the official docs.


Comments

Popular posts from this blog

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.Error occurred in starting fork -

windows - Debug iNetMgr.exe unhandle exception System.Management.Automation.CmdletInvocationException -

configurationsection - activeMq-5.13.3 setup configurations for wildfly 10.0.0 -