How to handle null value in realm.io?

from what I can see, if the value is nil for a property, it always throws an exception. sometimes I can't just set "empty string as nil", so what's the solution in scope? thank.

+3


source to share


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







All Articles