-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Swift default value of nil with optional flag not recognized, fails #1024
Comments
If I create the FlashCard instance within the transaction block nothing changes. I still receive the same error. Is it not possible to allow a default value of nil for a property? In this case not having a date set is important since it indicates that object hasn't been reviewed yet so I won't to allow for that case. |
Optional properties aren't really supported in Realm Swift. They are, but only if the property has a default value and the property is never set to nil. This is a duplicate of #628. Relationships can be nil though. i.e. |
Optional properties are not supported yet, except for RLMObject properties. It is very high on the list, though. But what you can do is to wrap the date in an RLMObject subclass, and let that property be optional:
|
Thanks @jpsim and @GreatApe! This actually won't be much of a problem as I can work around it by using other properties on the object. Allowing nil would have simplified the queries but testing against other properties is just as clear so this isn't a huge deal. Also in fact its better, rather not have to worry about nils. Closing as a duplicate of #628. |
I am attempting to do this with a float or double and I get the error My code:
What am I doing wrong? |
@scottfister could you please open a new issue with step-by-step instructions to reproduce the issue you're seeing? Thanks! |
If I have:
And then in a test case if I do the following:
I get the following error which is unexpected:
failed: caught "RLMException", "No value or default value specified for property 'lastReviewedAt' in 'FlashCard'"
since I set the value to nil and expect it at some points that it can be nil. Am I doing something wrong or is this default value not supported? Do I have to instantiate the FlashCard object within the block?The text was updated successfully, but these errors were encountered: