3

from what I see if the value is nil for a property it always throws exception. sometimes i cannot simply set a '' empty string as nil, so what's the solution in realm? thanks.

PeiSong
  • 1,005
  • 10
  • 16

1 Answers1

2

Null is now fully supported.

OLD answer:

Supporting nil/NULL is on the roadmap. Until then there are two workarounds:

  1. Add a separate property to indicate if your property is nil.

    @interface IntObject : RLMObject
    @property NSInteger myProp;
    @property boolean myPropIsNil;
    @end
    
  2. Wrap your property in an object:

    Object properties (links), can be nil though. So if you need a nullable int property, for example, you can wrap it in a new Realm model, like this:

    @interface IntObject : RLMObject
    @property NSInteger myProp;
    @end
    

    Then anytime you want to have an optional "int" property in your models, you can write this:

    @interface MyModel : RLMObject
    @property IntObject *optionalMyProp;
    @end
    
bmunk
  • 1,488
  • 1
  • 13
  • 22