How to handle null value in realm.io?
1 answer
Null is now fully supported.
OLD answer:
Supported nil / NULL in roadmap. Until then, there are two workarounds:
-
Add a separate property to indicate if your property is missing.
@interface IntObject : RLMObject @property NSInteger myProp; @property boolean myPropIsNil; @end
-
Wrap your property in an object:
Object properties (links) can be zero. So if you need a nullable int property, for example, you can wrap it in a new Realm model, for example:
@interface IntObject : RLMObject @property NSInteger myProp; @end
Then anytime you want to have an additional "int" property in your models, you can write this:
@interface MyModel : RLMObject @property IntObject *optionalMyProp; @end
+2
source to share