Define a custom getter
Kotlin has the convenience of custom computed properties in the form of custom getters. Here’s an example computed property from a real app I built which takes properties from a custom
Location class and returns a short description of that location.
Define a custom setter
A custom setter will be called every time a property’s value is set. In my app I need to sometimes save a search result and its type to a Realm database, but I cannot save enum values — only primitive types. So in this case when the enum value of
resultType is set, I also set a
restultTypeString property for if/when I need to save it in Realm.
To learn more about Kotlin getters and setters, visit the official docs.