EnumPersistable

public protocol EnumPersistable : Decodable, Encodable, Sendable

Protocol that represents a Codable Enum that can be persisted and easily integrate with remote APIs since it must have a raw String value.

That means only enums without associated values can be used as model properties.

  • Example:
public enum PostStatus: String, EnumPersistable {
    case draft
    case published
}

Warning

Although this has public access, it is intended for internal use and should not be used directly by host applications. The behavior of this may change without warning.

Note

Sendable because codegen’d enums stored on models conform to this, and Model is Sendable. Raw-value enums satisfy it without change.
  • Declaration

    Swift

    var rawValue: String { get }
  • Declaration

    Swift

    init?(rawValue: String)