Kheldar
Kheldar

Reputation: 5389

Why is my property absent from the Realm object?

I'm using Realm for persistence and I cannot access properties which are marked as readonly.

More accurately, I can print them using dot notation, but po object only shows the readwrite properties, and trying to access readonly properties using objectsWhere crashes.

I've tested using a standard NSObject class and the issue disappears (for po obviously), which makes me wonder why/if Realm ignores readonly properties?

Upvotes: 1

Views: 155

Answers (1)

TiM
TiM

Reputation: 15991

That's correct! If a property is marked as readonly, Realm ignores it and doesn't create a backing for it in the database file. This is the same implicit behavior as placing a method in the ignoredProperties method of RLMObject. They are left as traditional Objective-C properties. :)

If you need to make the property visible in the po object command, you can override the - (NSString *)description method of your object and ensure that your object is included in the description string that is printed.

Since readonly properties aren't backed by Realm, they'll be quite limited in what you can do with objectsWhere, as that uses a custom Realm query engine. You can probably check if other Realm properties match that property, but you couldn't create a query using the property itself as the item being searched for.

Upvotes: 2

Related Questions