CloudKitCodable
CloudKitCodable copied to clipboard
Add support for encoding/decoding String and Int enum properties
This introduces a couple of protocols, CloudKitStringEnum and CloudKitIntEnum.
When a model that conforms to CustomCloudKitCodable wants to encode/decode enum properties, the enums can adopt CloudKitStringEnum or CloudKitIntEnum and CoudKitRecordEncoder/Decoder will encode the values to the CKRecord as String and Int respectively.
Both enum protocols adopt CloudKitEnum, which has a single requirement:
public protocol CloudKitEnum {
static var cloudKitFallbackCase: Self? { get }
}
This allows enums to provide a fallback value in case decoding from an unsupported value fails because of new cases being added, for example.
There's a default implementation for enums that conform to CaseIterable that uses the first case as the fallback value.