jazzedge
11/29/2017 - 9:05 PM

Swift - CloudKit - Images & Large Files (Assets)

In addition to data, CloudKit may also be used to store larger assets such as audio or video 
files, large documents, binary data files or images. These assets are stored within CKAsset 
instances. Assets can only be stored as part of a record and it is not possible to directly 
store an asset in a cloud database. Once created, an asset is added to a record as just 
another key-value field pair. The following code, for example, demonstrates the addition 
of an image asset to a record:

let imageAsset = CKAsset(fileURL: imageURL)

let myRecord = CKRecord(recordType: "Vacations")

myRecord.setObject("London" as CKRecordValue?, forKey: "city")
myRecord.setObject(imageAsset as CKRecordValue?, forKey: "photo")