I came across a strange thing, trying to get an object from my Realm (iOS, Swift, Realm version 0.98.2)
print("speaker:") print(RealmProvider.appRealm.objects(FavoriteSpeaker).first!)
Correctly resets my object in the console:
speaker: FavoriteSpeaker { name = Ashley Nelson-Hornstein; }
But when I try to get the value of the name property:
print("speaker name:") print(RealmProvider.appRealm.objects(FavoriteSpeaker).first!.name)
I get an empty string 🤔
speaker name:
Four lines combined in my init method
Update 1 . I found an answer that assumes that you simply do not see the value when printing in the console: The Realm object is missing all properties except primaryKey , but I also tried to display the name property through the warning view, and also empty.
Update 2 . To make sure everything happens sequentially and in the same thread, I did this:
let favorite1 = FavoriteSpeaker() favorite1.name = "Debbie Downer" try! RealmProvider.appRealm.write { RealmProvider.appRealm.deleteAll() RealmProvider.appRealm.add(favorite1) } print("speaker:") print(RealmProvider.appRealm.objects(FavoriteSpeaker.self).first!) print("speaker name:") print(RealmProvider.appRealm.objects(FavoriteSpeaker.self).first!.name)
But the result is the same - printing name prints an empty string
swift realm
Marin todorov
source share