Realm-cocoa: version 4.0.0 does not support Enum objects

Created on 10 Nov 2019  Â·  4Comments  Â·  Source: realm/realm-cocoa

Bugs: After upgrading to Realm 4.0 for Swift, enum are not supported as they used to

Expected Results

enum to be supported as it was in version 3.21.0

Actual Results

*** Terminating app due to uncaught exception 'RLMException', reason: 'Property UserCard.cardType is declared as CardType, which is not a supported managed Object property type. If it is not supposed to be a managed property, either add it toignoredProperties()or do not declare it as@objc dynamic. See https://realm.io/docs/swift/latest/api/Classes/Object.html for more information.'

Steps to Reproduce

Code Sample

Enum is defined the following way

@objc enum CardType: Int {
    case type1
    case type2
    case type3
}
final class UserCard: Object {

    @objc dynamic var cid: String?
    @objc dynamic var cardType: CardType = .type3
    @objc dynamic var created_at = Int()
    @objc dynamic var updated_at = Int()
    @objc dynamic var md5: String?

    override static func primaryKey() -> String? {
        return "cid"
    }
}

Version of Realm and Tooling

Realm framework version: 4.0.0

Xcode version: 11.2.1

iOS/OSX version: 12.1

Dependency manager + version: cocoapod 1.8.4

O-Community

Most helpful comment

This is one of those things that worked by coincidence rather than being intentionally supported, and so broke when changing things. #6343 adds explicit support for @objc enum properties, although the enum will need to explicitly conform to the RealmEnum protocol (which doesn't require defining any methods).

This would be great to add to the Change Log or Release Notes. I had to follow some breadcrumbs to get here and discover the existence of RealmEnum.

All 4 comments

The same problem is here =((((

This is one of those things that worked by coincidence rather than being intentionally supported, and so broke when changing things. https://github.com/realm/realm-cocoa/pull/6343 adds explicit support for @objc enum properties, although the enum will need to explicitly conform to the RealmEnum protocol (which doesn't require defining any methods).

➤ Unito Sync Bot commented:

Transition made by Unito

This is one of those things that worked by coincidence rather than being intentionally supported, and so broke when changing things. #6343 adds explicit support for @objc enum properties, although the enum will need to explicitly conform to the RealmEnum protocol (which doesn't require defining any methods).

This would be great to add to the Change Log or Release Notes. I had to follow some breadcrumbs to get here and discover the existence of RealmEnum.

Was this page helpful?
0 / 5 - 0 ratings