-1

I am trying to create an inheritance for below enum

enum BankAuthError: String {
    case authFailed = "AuthFailed"
    case technicalError = "Unavailable"
    case accountLocked = "Locked"
    case unknownError = "UnknownError"
    case userInteractionRequired = "UserInteractionNeeded"
    case realmUserAlreadyConnected = "UserExists"
}

I am able to use this enum as below

let errorCode = BankAuthError(rawValue:errorMessageCodeString)

Now I am trying to create inheritance from above struct as below

//MARK:- Enum to handle all sysnc errors
enum SyncErrorStatus: BankAuthError {
 case usernameOrPasswordMissing = "UsernameOrPasswordMissing"
 case signatureMissing = "SignatureMissing"
 case twoPhaseAuthentication = "TwoPhaseAuth"
}

But if I am doing this, I am getting the compiler error as

'SyncErrorStatus' declares raw type 'BankAuthError', but does not conform to RawRepresentable and conformance could not be synthesized

Please let me know whether can we create inheritance from above Raw enum or not.

1
  • Enums are value types, so they don't support inheritance. Possible duplicate of Swift enum inheritance Commented Apr 2, 2019 at 9:42

1 Answer 1

6

Enums are value types, so there's no such thing as inheritance for enums. When you declare an enum as enum YourEnum: Type, you declare the rawValue of your enum to be of type Type. However, Type needs to conform to RawRepresentable.

What you are looking for, to create an enum that contains all cases of another enum, plus some other cases in currently not possible in Swift. You cannot inherit all cases of an enum.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.