CKAsset will not be displayed in table format

I have an optional image in Cloudkit (a verified DB and the image is where I added it in my testing). I created a class that initializes the record fields in the variables that I use in my table view. I also have a custom cell. But the image will not display in my custom tableview cell. I do not know if there is a problem with an additional image in the table image, or if there is a problem with my code / settings in cloudkit.

Any help is greatly appreciated since I was stuck for a week and there is nothing to know about it on the Internet.

Here is my class code:

var feedResults = [UserPosts]()

class UserPosts {

var record: CKRecord
var description: String
var username: String
//var image: CKAsset? // tried also initializing the CKAsset separately
var postPic: UIImage?


init(record: CKRecord) {

    self.record = record
    self.description = record.objectForKey("description") as String
    self.username = record.objectForKey("username") as String
   // self.image = record.objectForKey("postPic") as? CKAsset


    if var pic = record.objectForKey("postPic") as CKAsset! {

           self.postPic = UIImage(contentsOfFile: pic.fileURL.path!)

            // below is the other way I've seen it done.
               // var url = pic.fileURL!
               // var imageData = NSData(contentsOfFile: url.path!)
              // self.postPic = UIImage(data: imageData!)

    }
}

}

Here is my table code:

    override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as TableViewCell

    let record = feedResults[indexPath.row]
    cell.postDescription.text = record.description
    cell.userName.text = record.username

    if record.postPic != nil {

         cell.postPic.image = record.postPic!

    }

    return cell
}

CKAset UIImage. - , , Apple CloudKitAtlas. Obj-C, , - CloudKitAtlas

, NSData (contentOFFile:) UIImage (:), : SO CKAsset

+4
2

.paths contentsOfURL. ( if CKAsset):

         if var data = NSData(contentsOfURL: pic!.fileURL) {
            self.postPic =  UIImage(data: data!)!
        }

... dequeueReusableCellWithIdentifier, , . nil

+3

CKAsset :

    var img = record.valueForKey("Picture") as? CKAsset
    cell.imageView?.image = UIImage(contentsOfFile: img!.fileURL.path!)

, !

+1

All Articles