Skip to content
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

RealmableEnum not able to determine RawValue #67

Open
DantePuglisi opened this issue Dec 27, 2021 · 0 comments
Open

RealmableEnum not able to determine RawValue #67

DantePuglisi opened this issue Dec 27, 2021 · 0 comments

Comments

@DantePuglisi
Copy link

I'm having a crash that reads:

*** Terminating app due to uncaught exception 'RLMException', reason: 'Property 'enumType' is declared as 'MyEnum', which is not a supported RLMObject property type. All properties must be primitives, NSString, NSDate, NSData, NSNumber, RLMArray, RLMSet, RLMDictionary, RLMLinkingObjects, RLMDecimal128, RLMObjectId, or subclasses of RLMObject. See https://realm.io/docs/objc/latest/api/Classes/RLMObject.html for more information.'

I suspect it's because I have this init in MyEnum which I can't change (because it's used in other targets I don't have access to). What could be the cause? I spent some time trying to determine the issue and discovered that inside the Realm framework on (BOOL)setTypeFromRawType:(NSString *)rawType in RLMProperty rawType is @\MyEnum\ which is wrong because all others are some variation of ObjC primitive types.

Here's my enum code:

public enum MyEnum: String, RealmableEnum {
    case blue
    case red
    case unknown
    
    // MARK: - Initialization
    
    public init(rawValue: String) {
        let lowercased: String = rawValue.lowercased()
        switch lowercased {
            case Self.red.rawValue: self = .red
            case Self.blue.rawValue: self = .blue
            default: self = .unknown
        }
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant