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
Related Q & A:
- How can I optimize this dynamic SQL query in oracle with PL/SQL?Best solution by docs.oracle.com
- How can I convert Matlab code to c#?Best solution by Stack Overflow
- How do I get the code for my radio in my Renault Clio?Best solution by Yahoo! Answers
- How do I get the code for the Jumbo remote?Best solution by jumboremotecontrol.com
- How do I change the date to the correct one?Best solution by answers.yahoo.com
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
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.