Why do I get value by KVC but not by using properties while using Realm?

188 views Asked by At

I am trying Realm(installed using pods). I am using Swift 3 with Xcode 8.1.

My code looks like this-

    do {
        let realm = try Realm()
        let human = Human()
        human.name = "Nikhil"
        human.legs = 2

        try realm.write {
            realm.add(human)
        }

        let humans = realm.objects(Human.self)
        for h in humans {
            print("\(h.name)") //Here is breakpoint
        }
    } catch {
        //
    }

And then I do

(lldb) po h.name
""


(lldb) po h.value(forKey: "name")!
Nikhil

Why are properties not returning values but I can retrieve values by value(forKey:?

1

There are 1 answers

0
Nikhil Manapure On BEST ANSWER

As stated by @kishikawa katsumi -

Class properties should have been defined as dynamic.

A big thanks to him for pointing that mistake.