i've create an extension, i hope it will help you
import RealmSwift
protocol RealmPersistableEnum: RawRepresentable, _OptionalPersistable { }
extension RealmPersistableEnum where RawValue: _OptionalPersistable {
static func _rlmGetProperty(_ obj: ObjectBase, _ key: PropertyKey) -> Self {
Self(rawValue: RawValue._rlmGetProperty(obj, key)) ?? Self()
}
static func _rlmGetPropertyOptional(_ obj: ObjectBase, _ key: PropertyKey) -> Self? {
guard let value = RawValue._rlmGetPropertyOptional(obj, key) else { return nil }
return Self(rawValue: value)
}
static func _rlmSetProperty(_ obj: ObjectBase, _ key: PropertyKey, _ value: Self) {
RawValue._rlmSetProperty(obj, key, value.rawValue)
}
}
Use example
enum SomeEnumInt: Int, RealmPersistableEnum {
case none = 0
case test = 1
case debug = 2
init() {
self = .none
}
}
enum SomeEnumString: String, RealmPersistableEnum {
case none
case test
case debug
init() {
self = .none
}
}
class Foo: Object {
@Persisted var v1: String
@Persisted var v2: SomeEnumInt
@Persisted var v3: SomeEnumString
}
@objc
if it is anInt
enum. – Enclasp