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.
Asked
Active
Viewed 3,361 times
1 Answers
2
Null is now fully supported.
OLD answer:
Supporting nil/NULL is on the roadmap. Until then there are two workarounds:
Add a separate property to indicate if your property is nil.
@interface IntObject : RLMObject @property NSInteger myProp; @property boolean myPropIsNil; @end
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
-
3though this works it's not natural at all. looking forward to the support of nil value. thanks. – PeiSong Oct 20 '14 at 09:19
-
1Is there any date for this feature to be included?? – sgallego Jan 05 '15 at 10:42
-
Unfortunately no official dates we can share yet. But it's being worked on actively at the core engine level. – bmunk Jan 05 '15 at 13:10
-
Note: if you want to be able to sort by your property value, don't use the wrap workaround (2) since there is no support for multilevel keypath sorting. – Sebastien Windal May 11 '15 at 22:50
-
Absolutely! Null values has been supported for a while now :-) – bmunk Jun 06 '16 at 12:46