A have a CKRecord which contains details of a course, I can fetch all the records and manipulate them as required within a particular view. I am having a little problem with the CKAsset, which is a pdf. My image CKAsset fetch and display in a UIImageView works fine -
let coverPhoto = record.object(forKey: "courseImage") as? CKAsset
if let asset = coverPhoto {
if asset != nil {
let photoData : NSData? = NSData(contentsOf:asset.fileURL)
self.cseImageView.image = UIImage(data:photoData! as Data)
}
}
However I am unsure how to finish the code when it comes to the pdf - this is my attempt, which is incomplete (indicated by the ?????)
if let asset = record.object(forKey: "courseDocument1") as? CKAsset {
if asset != nil {
let docData : NSData? = NSData(contentsOf:asset.fileURL)
self.couseDocWebView.?????? = (docData, MIMEType:"application/pdf")
}
}
I guess my question is, am I close or way off the mark, and if so - any pointer?
Thank you
After much debate and trying a variety of scripts, the following code works in Swift 3 -
I think it was just the order in which the data is called and presented with a referring URL from the CKAsset path.