Get object property. The property is another object.
Expecting a valid object.
Returning nil.
The result of this
...
print(localChat.description)
print(localChat.lastMessage?.description)
print(localChat.description)
....
Chat {
id = 2204602d-aca2-4566-ae49-70ffa2e2cab8;
lastMessage = Message {
id = 6EE4C3DC-6D29-431D-A175-D359EA782AAF;
};
}nil
Chat {
id = 2204602d-aca2-4566-ae49-70ffa2e2cab8;
lastMessage = Message {
id = 6EE4C3DC-6D29-431D-A175-D359EA782AAF;
};
}Version of Realm and Tooling
In the CONTRIBUTING guidelines, you will find a script,
which will help determining these versions.
Realm version: 0.98.7
Xcode version: 7.3 (7D175)
iOS/OSX version: 10.11.4
Dependency manager + version: cocoapods 0.39.0
@georgepoenaru
I believe you forgot to specify dynamic to lastMessage property. If there is no dynamic attribute on the property, the Realm object cannot invoke Realm's getter method due to dispatch statically by Swift compiler. (description method invoke valueForKey() method internally, it occurs dynamic dispatch. that's why you can see the lastMessage value in the description)
So could you confirm setting dynamic attributes on your model definition?
class Chat: Object {
...
dynamic var lastMessage: Message?
...
}
NOTE: RealmOptional and List<T> properties cannot be set dynamic.
See also property cheetsheet: https://realm.io/docs/swift/latest/#cheatsheet
Thank you! This was my problem. I thought that object properties can't also be set dynamic.
Most helpful comment
@georgepoenaru
I believe you forgot to specify
dynamictolastMessageproperty. If there is nodynamicattribute on the property, the Realm object cannot invoke Realm's getter method due to dispatch statically by Swift compiler. (descriptionmethod invokevalueForKey()method internally, it occurs dynamic dispatch. that's why you can see thelastMessagevalue in thedescription)So could you confirm setting
dynamicattributes on your model definition?NOTE:
RealmOptionalandList<T>properties cannot be setdynamic.See also property cheetsheet: https://realm.io/docs/swift/latest/#cheatsheet