How to handle null value in realm.io?

感情迁移 提交于 2019-12-10 20:34:17

问题


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:

  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
    


来源:https://stackoverflow.com/questions/26458585/how-to-handle-null-value-in-realm-io

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!