I'm using Realm
with Codeable
. I noticed that Bool
& Int
attributes aren't added to the table in Realm Browser
as shown in ScreenShot.
How to fix this issue?
Asked
Active
Viewed 224 times
0

Emy Alsabbagh
- 287
- 1
- 3
- 8
-
1Bool and Int properties can not be declared as optional in Realm. Only "String, NSDate, and NSData properties can be declared as optional" - from the Realm documentation. See my answer here: https://stackoverflow.com/a/59323939/10706839 – lajosdeme Feb 06 '20 at 11:57
-
@lajosdeme hmm **Storing optional numbers is done using RealmOptional.** For example `let age = RealmOptional
()` which is an optional Int. – Jay Feb 06 '20 at 17:09 -
It's a good idea an best practice here on SO to post code and models as text, not screenshots. That way we can copy and past if we need to use them in an answer instead of retyping. See [images and links are evil](http://idownvotedbecau.se/imageofcode) – Jay Feb 06 '20 at 17:14
1 Answers
0
To make optional int's and bool's in Realm, they must be defined as RealmOptional.
So update your model like this
@objcMembers class CategoryDoc: Object: Codeable {
dynamic var name: String?
let isActive = RealmOptional<Int>()
let v = RealmOptional<Bool>()

Jay
- 34,438
- 18
- 52
- 81