diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 0000000..d973452 --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1 @@ +github: insidegui diff --git a/Package.swift b/Package.swift index c5a8e6a..678d0fc 100644 --- a/Package.swift +++ b/Package.swift @@ -7,7 +7,7 @@ let package = Package( .macOS(.v11), .iOS(.v14), .tvOS(.v14), - .watchOS(.v5) + .watchOS(.v7) ], products: [ .library(name: "CloudKitCodable", targets: ["CloudKitCodable"]) diff --git a/Sources/CloudKitCodable/CloudKitRecordDecoder.swift b/Sources/CloudKitCodable/CloudKitRecordDecoder.swift index 029384c..6ee3cd6 100644 --- a/Sources/CloudKitCodable/CloudKitRecordDecoder.swift +++ b/Sources/CloudKitCodable/CloudKitRecordDecoder.swift @@ -131,8 +131,6 @@ extension _CloudKitRecordDecoder.KeyedContainer: KeyedDecodingContainerProtocol func decode(_ type: T.Type, forKey key: Key) throws -> T where T : Decodable { try checkCanDecodeValue(forKey: key) - print("decode key: \(key.stringValue)") - if key.stringValue == _CKSystemFieldsKeyName { return systemFieldsData as! T } @@ -235,7 +233,9 @@ extension _CloudKitRecordDecoder.KeyedContainer: KeyedDecodingContainerProtocol let data = try Data(contentsOf: url) - return try T.decoded(from: data, type: contentType) + /// Don't use dynamic content type (which is the type when `URL` can't figure out its type). + let effectiveType = contentType.isDynamic ? T.preferredContentType : contentType + return try T.decoded(from: data, type: effectiveType) } private func decodeURL(from asset: CKAsset) throws -> URL { diff --git a/Sources/CloudKitCodable/Documentation.docc/DataTypes.md b/Sources/CloudKitCodable/Documentation.docc/DataTypes.md index 45e1ead..1c964dd 100644 --- a/Sources/CloudKitCodable/Documentation.docc/DataTypes.md +++ b/Sources/CloudKitCodable/Documentation.docc/DataTypes.md @@ -39,3 +39,13 @@ Sometimes models have properties that use small value types with a few of their To enable this, CloudKitCodable will detect properties that have a custom `Codable` type and set the corresponding `CKRecord` field to be a `Data` value with the JSON-encoded representation of the value. > Important: If your model has a property with a `Codable` type that can potentially become large when encoded, or if your model has more than a couple of properties with `Codable` types, then you should adopt ``CloudKitAssetValue`` instead so that the properties can be represented as a `CKAsset`, which doesn't run the risk of bumping into the 1MB per-record size limit. + +### Arrays + +All primitive types that are supported in `CKRecord` array fields are also supported by CloudKitCodable. + +Nested codable values can also be stored as an array, which will become an array of JSON-encoded `Data` in the `CKRecord`. + +> Note: Types conforming to ``CloudKitAssetValue`` **are not** currently supported in arrays. + +> Note: Collection types other than `Array` are not supported.