Ckasset in Server Record Contains No Fileurl, Cannot Even Check for Nil

Curious whether fileUrl of CKAsset can change with time?

The fileURL of an asset will not change, but if this is an asset you downloaded from the server the data is only guaranteed to exist at that location until the completion block of the operation is called. After that point the asset's backing file may be cleaned up at any time to free up disk space.

After downloading an asset from the server you should move or copy the backing file to another location in your application's container if you'd like to keep it.

CKAsset not Saved to CloudKit - All other fields are saved

user3069232 should get credit for the answer. The code above does save
the record to CloudKit before the image file save has completed. I moved
the CloudKit save block inside the do catch block and the process is
successful. Since I'm guaranteed to have an image in all records (there
is a default) then making the CloudKit save conditional on having a
successful image save is ok.

Using Cloudkit Assets as a UIimage

Maybe the problem is that the CKAsset record is nil, but you are forcing to have a fileURL value.

Try to obtain CloudKit image with this snippet

if let asset = record["myImageKey"] as? CKAsset,
let data = try? Data(contentsOf: (asset.fileURL)),
let image = UIImage(data: data)
{
self.detailImage.image = image
}

recovering errors with CKPartialErrorsByItemIDKey

According to the documentation, you get back an NSDictionary, not a Swift dictionary.

Try:

if let dictionary = error.userInfo[CKPartialErrorsByItemIDKey] as? NSDictionary {
print("partialErrors #\(dictionary.count)")
}


Related Topics



Leave a reply



Submit