0

After struggling to create Realm object in App Group, I seem to have hit the next issue.

Objects that save into Realm with no issues when in Documents directory does not seem to save when in App Groups.

realm.transactionWithBlock { () -> Void in  
  let testModel = TestModel(test: "xyz")    
  self.realm.addObject(testModel)  
}

Is this a known issue?

Community
  • 1
  • 1
Prasanna
  • 688
  • 1
  • 9
  • 27
  • Did you try creating an empty file at that location to make sure the app group was created properly? http://stackoverflow.com/questions/27355557/how-to-set-default-realm-path-to-app-groups-directory/27369606#comment43224005_27369606 – jpsim Dec 15 '14 at 20:57
  • Yes. App group is created properly. Realm file is also created, along with realm objects. But no records are being saved. – Prasanna Dec 15 '14 at 20:59
  • Can you please create a sample project for us to be able to replicate the issue? A GitHub repo works, or you can email it to us at help@realm.io – jpsim Dec 15 '14 at 21:04
  • I created a simple project and data stores without issues in App Groups. I will investigate further and report back. Thanks! – Prasanna Dec 18 '14 at 11:50
  • Did you find out anything interesting? – jpsim Dec 19 '14 at 20:52
  • @Prasanna Got any solution ? – Alizain Prasla Jun 25 '20 at 17:16

1 Answers1

0

All mutations including adds must happen in a write transaction. Like this:

self.realm.transactionWithBlock() {
    self.realm.addObject(testModel)
}
bmunk
  • 1,488
  • 1
  • 13
  • 22