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.
This introduces a couple of protocols,
CloudKitStringEnum
andCloudKitIntEnum
.When a model that conforms to
CustomCloudKitCodable
wants to encode/decode enum properties, the enums can adoptCloudKitStringEnum
orCloudKitIntEnum
andCoudKitRecordEncoder/Decoder
will encode the values to theCKRecord
asString
andInt
respectively.Both enum protocols adopt
CloudKitEnum
, which has a single requirement: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.