realm / realm-swift

Realm is a mobile database: a replacement for Core Data & SQLite
https://realm.io
Apache License 2.0
16.27k stars 2.14k forks source link

Could swift enums + index be made possible with @Persisted? #7404

Closed automactic closed 3 years ago

automactic commented 3 years ago

!!! MANDATORY TO FILL OUT !!!

Goals

It would be great to make it possible to add index to a swift enum property. (Or if someone can confirm we have no plan to support this)

Expected Results

Make it possible to use @Persisted(indexed: true) var property: EnumType with enum EnumType: String/Int/..., PersistableEnum.

Actual Results

An compile error was produced: Referencing initializer 'init(wrappedValue:indexed:)' on 'Persisted' requires that 'EnumType' conform to '_Indexable'

Steps for others to Reproduce

Code Sample

class Entity: Object {
    @Persisted(indexed: true) var category: Category
    enum Category: String, PersistableEnum {
        case a, b, c, d
    }
}

Version of Realm and Tooling

Realm framework version: 10.12

Xcode version: 12.5.1

iOS/OSX version: iOS 14.7

Dependency manager + version: SwiftPackageManager

tgoyne commented 3 years ago

This should be pretty trivial to allow and not supporting it was just an oversight.

automactic commented 3 years ago

Thanks for your super quick response, that's what I thought.