问题
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.
回答1:
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; @endWrap 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; @endThen anytime you want to have an optional "int" property in your models, you can write this:
@interface MyModel : RLMObject @property IntObject *optionalMyProp; @end
来源:https://stackoverflow.com/questions/26458585/how-to-handle-null-value-in-realm-io