Swift Realm: After writing transaction reference set to nil

前端 未结 2 1756
轮回少年
轮回少年 2021-01-16 06:30

I have the following code

class Family: Object {
    dynamic var name = \"\"
    var members = List()
}

class FamilyMember: Object {
            


        
相关标签:
2条回答
  • 2021-01-16 07:18

    Can you try removing the line

    realm.add(newFamily)
    

    from your write block?

    0 讨论(0)
  • 2021-01-16 07:33

    It's intended behavior. Realm does not copy any data until actually access the properties. When access the properties, Realm fetch the data directly from its file. So Realm does not store any data to its ivar. Additionally, Realm object will change to another class at the moment it is persisted. That's why you cannot see any values via the debugger and nil out all value after committed.

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

    See also https://realm.io/docs/swift/latest/#debugging

    Debugging apps using Realm’s Swift API must be done through the LLDB console.

    Note that although the LLDB script installed via our Xcode Plugin allows inspecting the contents of your Realm variables in Xcode’s UI, this doesn’t yet work for Swift. Instead, those variables will show incorrect data. You should instead use LLDB’s po command to inspect the contents of data stored in a Realm.

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

    0 讨论(0)
提交回复
热议问题