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
iOS 12 Wkwebview Not Working with Redirects
Xcode Failed to Resolve Dependency Firebase - Googleappmeasurement Does Not Match Requirement
How to Create Generic Convenience Initializer in Swift
Conversion Between Cgfloat and Nsnumber Without Unnecessary Promotion to Double
Avspeechrecognizer: Required Condition Is False: _Recordingtap == Nil Error in Swift3
Why This Line Is Not Covered? Xcode Code Coverage
How to Keep a User Logged In? Swift
How to Distinguish Bool and Int in Swift
How to Create a Single Page Vertical Scrolling Pdfview in Swift
How to Override Setter in Swift
Why Does Compactmap Return a Nil Result
How to Initialize UIbezierpath to Draw a Circle in Swift
Tableview.Cellforrowatindexpath(Indexpath) Return Nil
Viewwilllayoutsubviews in Swift
Ambiguous Reference to Member 'Buildblock()'
How to Set First Responder for Nstextview in Swift
How to Call Completionhandler for Performfetchwithcompletionhandler in Swift