Unrealm icon indicating copy to clipboard operation
Unrealm copied to clipboard

Bool can't add to realm

Open IAFung opened this issue 2 years ago • 4 comments

When Bool default value is 'true', can't save to realm I changed the demo

struct ToDoItem: Realmable {
    var id = UUID().uuidString
    var text = ""
    var isCompleted = true //modified this default value
    
    static func primaryKey() -> String? {
        return "id"
    }
}

when I set the 'isCompleted' default value is true. can't save the false to the realm

IAFung avatar Oct 26 '21 07:10 IAFung

Can you post an example code, please?

arturdev avatar Oct 26 '21 08:10 arturdev

I used your Example 截屏2021-10-26 下午6 05 03 I just modified the isCompleted to true Then run the demo https://user-images.githubusercontent.com/13991864/138857898-986dc4db-272f-423e-8876-3d5967cad9bf.mov The isCompleted can't set to false

IAFung avatar Oct 26 '21 10:10 IAFung

You're right. Currently, as a workaround, you can make an init method that takes it as true by default, and leave it false in the definition.

arturdev avatar Oct 28 '21 16:10 arturdev

I got here because Realmable structs are requesting to create an empty init otherwise they don't comply to Realmable. What's the cause for the issue explain here (and the init issue too)? Maybe they're related @arturdev?

DantePuglisi avatar Dec 27 '21 13:12 DantePuglisi