What's New / App Services, Foundation & Diagnostics

What's new in CloudKit

+2 NewiOS · macOS · tvOS · watchOS

CloudKit stores structured records and binary assets in iCloud containers, syncs them across a user's devices, and shares them between users. CKAsset wraps file data attached to a record.

Two additions, no deprecations or removals. The new struct ExportedAssetID identifies an asset outside the normal record fetch path, and there is a new CKAsset.init.

New

2
struct

CKAsset.ExportedAssetID

NewiOSmacOStvOSwatchOS
public struct ExportedAssetID : Codable, Sendable

An identifier that can be used for creating a server-side copy of a CKAsset that already exists in iCloud, potentially in a different container.

An ExportedAssetID is valid only on the same device where it was created, and it expires after a few days.

Declaration
public struct ExportedAssetID : Codable, Sendable {

    /// Creates a new instance by decoding from the given decoder.
    ///
    /// This initializer throws an error if reading from the decoder fails, or
    /// if the data read is corrupted or otherwise invalid.
    ///
    /// - Parameter decoder: The decoder to read data from.
    public init(from decoder: any Decoder) throws

    /// Encodes this value into the given encoder.
    ///
    /// If the value fails to encode anything, `encoder` will encode an empty
    /// keyed container in its place.
    ///
    /// This function throws an error if any values are invalid for the given
    /// encoder's format.
    ///
    /// - Parameter encoder: The encoder to write data to.
    public func encode(to encoder: any Encoder) throws
}
init

CKAsset.init

NewiOSmacOStvOSwatchOS
public convenience init(importing exportedAssetID: CKAsset.ExportedAssetID)

Initialize a new CKAsset that can be used to create a copy of an asset that already exists in iCloud, potentially in a different container.

When this asset is saved, a server-side copy of the referenced asset is created.

The new CKAsset does not reference any data on the local device (its fileURL is nil).

When you assign this asset to a field in a CKRecord and save the record, the CloudKit server creates a new asset by copying the contents of the asset identified by the exportedAssetID.

If the source asset no longer exists on the server, saving the record fails with unknownItem.

If the exportedAssetID is invalid or expired, saving the record fails with assetNotAvailable.

Assets created this way are supported starting with iOS 17.0, macOS 14.0, tvOS 17.0, watchOS 10.0, and visionOS 1.0. Devices running older OS versions may fail to download the created asset.

Parameters

exportedAssetID
Identifies the source asset that this CKAsset will copy. The exportedAssetID is only valid on the same device it was created, and it expires after a few days.

No APIs match your filter.

← More in App Services, Foundation & Diagnostics