2

Let's say I have the following enums:

enum UserState {
    case LoggedIn(LoggedInState)
    case LoggedOut(LoggedOutState)
}

enum LoggedInState {
    case Playing
    case Paused
    case Stopped
}

enum LoggedOutState {
    case Unregistered
    case Registered
}

Is there a way to save UserState to UserDefaults ?

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Adrian
  • 19,440
  • 34
  • 112
  • 219
  • Does [this](https://stackoverflow.com/questions/45441946/how-do-i-save-an-enum-case-value-to-userdefaults-for-further-usage) help? – Daniel Jan 19 '18 at 20:06

1 Answers1

1

Yes

You can use Codable protocol to transform your enum into a representation that can be saved in UserDefaults. This tutorial might give you a kickstart.

Rafał Sroka
  • 39,540
  • 23
  • 113
  • 143