1

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
  • Ben, once you get passed finding your way around, in practice you will have to use DLImageLoader (which, thank God, is now available in Swift). (Or indeed some other image caching library.) It's not possible to make realistic projects, other than just "Hello world" demos, without it. Commented Sep 20, 2015 at 21:58

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

3 Comments

Hey, thanks for the reply. I now get an error saying Segmentation fault 11, as well as this message at the top of the ViewController.swift: "xcode encountered a problem source editor functionality is limited". All of the code inside the vc.swift goes black too and there is a load icon saying "Indexing". This is something to do with the "query.findObjectsInBackgroundWithBlock { ... Void in" line. Any ideas?
AHH! @BenJameson, that's an annoying RECENT KNOWN PROBLEM in the Parse milieu. in short REPLACE AnyObject WITH PFObject and it will eliminate the bizarre seg fault problem! Hope it helps! example
Finally been able to do it! Thanks both of you

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.