How can I query Parse data by creation date with Swift?

How do i change this code to query by creation date with swift from parse data?

  • I have this code to retrieve images from parse data. How do I query it by creation date? I tried using findObjectsInBackgroundWithBlock but it wont work with a PFFile. What do i do? Also, as a side question, sometimes when i place the images in a UIImageView they are upside down or sideways. Why? if let objects = objects as? [PFObject] { for object in objects { if let userPicture = object.valueForKey("Image") as? PFFile { userPicture.getDataInBackgroundWithBlock({ (imageData: NSData?, error: NSError?) -> Void in if (error == nil) { let image = UIImage(data:imageData!) self.ImageArray.insert(image!, atIndex: 0) } else { self.alert("Error: \(error!) \(error!.userInfo!)", Message: "Make sure you have a secure internet connection") } dispatch_async(dispatch_get_main_queue()) { self.collectionView.reloadData() println("Finished Pictures") } }) } }}

  • Answer:

    You have a set of objects which all reference an image file, but probably a set of other things too, and the image can likely be changed. So, the object creation date isn't the same as the image creation date and the image file doesn't know (or at least doesn't expose) it's creation date. You're also currently always adding the images to the start of the array so the position will be set by how big (and therefore how long it takes to download) each image is. Also, trying to download lots of images at the same time could just mean you get lots of timeouts. So, really you should have a column on your object which holds the date at which the image was updated, and sort the objects by that date. As you download the images you place them into the image array in the same index as the owning object in its array (pad the array out with NSNull so you know what's going on).

nachshon fertel at Stack Overflow Visit the source

Was this solution helpful to you?

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.