How do I display an image from Parse in a UIImageView (Swift)?

孤者浪人 提交于 2019-12-23 01:25:48

问题


I am fairly new to both Swift and Parse, and I am trying to display an image I have uploaded to Parse (through Parse, not through my app) in my app as a UIImageView. The idea is that I will be able to change the image via Parse if I want and display it in the same single UIImageView in the app -- literally just need the code to retrieve an image in Parse to UIImageView.

I have searched for ages for an answer to this but have not found one, even though it seems like it should be so easy; maybe it's just my frustration that is stopping me from doing it!? I have been able to query string before from Parse for instance, but cannot find a way to do so with an image file and I am now at the point where I don't even know where to start with the code!

An answer would be greatly appreciated!!!


回答1:


You were on the right track using a query. Try this:

var query = PFQuery(className:"YourClassName")
query.findObjectsInBackgroundWithBlock {

/// (objects: [AnyObject]?, error: NSError?) -> Void in

// NOTE 9/2015.  MUST BE "PFObject" ...... "AnyObject" does NOT work.
// "AnyObject" causes a segmentation fault on build

(objects: [PFObject]?, error: NSError?) -> Void in

if error == nil {
  // The find succeeded.
  println("Successfully retrieved \(objects!.count) objects.")
  // Do something with the found objects
  if let objects = objects as? [PFObject] {
    for object in objects {
      println(object.objectId)//this just prints the object id
    }
  }
} else {
// Log details of the failure
  println("error occurred ")
}
}

Oh, and FYI the image itself will be a pffile. This code will retrieve the pfobject for you then you can get the pffile from that.



来源:https://stackoverflow.com/questions/32681737/how-do-i-display-an-image-from-parse-in-a-uiimageview-swift

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!