Swift Realm: After writing transaction reference set to nil -


i have following code

class family: object {     dynamic var name = ""     var members = list<familymember>() }  class familymember: object {     dynamic var name = ""     dynamic var belongstofamily: family? }  let realm = try! realm()  let familymember = familymember() familymember.name = "nameexample"  let newfamily = family() newfamily.name = "familyname"  try! realm.write {     newfamily.members.append(familymember)     familymember.belongstofamily = newfamily     realm.add(newfamily)     realm.add(familymember) } 

question: why familymember.belongstofamily set nil after realm's writing transaction?

it's intended behavior. realm not copy data until access properties. when access properties, realm fetch data directly file. realm not store data ivar. additionally, realm object change class @ moment persisted. that's why cannot see values via debugger , nil out value after committed.

so if you'd debug objects value, can use po command in debug console, or use print() method.

see https://realm.io/docs/swift/latest/#debugging

debugging apps using realm’s swift api must done through lldb console.

note although lldb script installed via our xcode plugin allows inspecting contents of realm variables in xcode’s ui, doesn’t yet work swift. instead, variables show incorrect data. should instead use lldb’s po command inspect contents of data stored in realm.

and see also: https://github.com/realm/realm-cocoa/issues/2777


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -