title: Query image and text from parse
body: <p>So I am create a application that users can upload images and text. The posts will be shown in UICollectionView I will provide some code for you to see below.</p>
  
  <p>So my PostsViewController looks something like this:</p>
  
  <pre><code>import UIKit
  import Parse
  import Bolts
  import ActiveLabel
  
  extension UILabel {
      func setSizeFont (sizeFont: CGFloat) {
          self.font =  UIFont(name: self.font.fontName, size: sizeFont)!
          self.sizeToFit()
      }
  }
  
  extension NSDate {
      var timeAgo: String {
          let minute = 60
          let hour = 60 * minute
          let day = 24 * hour
          let secondsAgo = Int(NSDate().timeIntervalSinceDate(self))
          if secondsAgo &lt; 0            { return  "later"                           }
          if secondsAgo == 0           { return "now"                              }
          if secondsAgo == 1           { return "1 second ago"                     }
          if secondsAgo &lt; minute       { return "\(secondsAgo) seconds ago"        }
          if secondsAgo &lt; (2 * minute) { return "1 minute ago"                     }
          if secondsAgo &lt; hour         { return "\(secondsAgo/minute) minutes ago" }
          if secondsAgo &lt; 2 * hour     { return "1 hour ago"                       }
          if secondsAgo &lt; day          { return "\(secondsAgo / hour) hours ago"   }
          let formatter = NSDateFormatter()
          formatter.dateFormat = "M/d/yy"
          return formatter.stringFromDate(self)
      }
  }
  
  extension UIImage {
      func makeImageWithColorAndSize(color: UIColor, size: CGSize) -&gt; UIImage {
          UIGraphicsBeginImageContextWithOptions(size, false, 0)
          color.setFill()
          UIRectFill(CGRectMake(0, 0, size.width, size.height))
          let image = UIGraphicsGetImageFromCurrentImageContext()
          UIGraphicsEndImageContext()
          return image
      }
  }
  
  struct Details {
      var username:String!
      var text:String!
      var CreatedAt:NSDate!
      var image:String!
      var objID:String!
      var likedBy:NSArray
      var comments:NSArray
      init(username:String,text:String,CreatedAt:NSDate,image:String,objID:String,likedBy:NSArray,comments:NSArray){
  
          self.username = username
          self.text = text
          self.CreatedAt = CreatedAt
          self.image = image
          self.objID = objID
          self.likedBy = likedBy
          self.comments = comments
      }
  }
  
  class HomeViewController: UIViewController, UICollectionViewDelegate, PlayerDelegate {
  
      @IBOutlet var collectionView: UICollectionView!
  
      var arrayOfDetails = [Details]()
      var likedPhotos = String()
  
      let Like = UIImage(named: "Like.png")
      let LikeDone = UIImage(named: "LikeDone.png")
  
      override func viewDidLoad() {
          super.viewDidLoad()
          // Do any additional setup after loading the view, typically from a nib.
  
          self.collectionView.delegate = self
  
          queryCurrentUploads()
  
      }
  
      override func didReceiveMemoryWarning() {
          super.didReceiveMemoryWarning()
          // Dispose of any resources that can be recreated.
      }
  
      func queryCurrentUploads() {
          self.arrayOfDetails.removeAll()
          let query = PFQuery(className: "currentUploads")
          query.orderByDescending("createdAt")
          query.findObjectsInBackgroundWithBlock { (objects:[PFObject]?, error: NSError?) -&gt; Void in
              if error == nil
              {
                  if let newObjects = objects {
  
                      for oneobject in newObjects {
                          let text = oneobject["imageText"] as! String
                          let username = oneobject["username"] as! String
                          let objID = oneobject.objectId!
                          let time = oneobject.createdAt!
                          let likedBy = oneobject["likedBy"] as! NSArray
                          let comments = oneobject["comments"] as! NSArray
  
  
                          if let userImage = oneobject["imageFile"] as? PFFile {
                              let userImage = oneobject["imageFile"] as! PFFile
  
                              let imageURL = userImage.url
                              let OneBigObject = Details(username: username, text: text, CreatedAt: time, image: imageURL!, objID: objID, likedBy: likedBy, comments: comments)
  
                              self.arrayOfDetails.append(OneBigObject)
  
                              dispatch_async(dispatch_get_main_queue()) { self.collectionView.reloadData() }
                          }
                      }
                  }
              }
          }
      }
  
      func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -&gt; Int
      {
          return self.arrayOfDetails.count
      }
  
      func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -&gt; UICollectionViewCell
      {
          let imageCell = collectionView.dequeueReusableCellWithReuseIdentifier("imageCell", forIndexPath: indexPath) as? CollectionViewCell
  
          let post = self.arrayOfDetails[indexPath.row]
  
          imageCell?.flagContentButton.titleLabel?.adjustsFontSizeToFitWidth = true
          imageCell?.uploadedTimeLabel.adjustsFontSizeToFitWidth = true
          imageCell?.commentsButton.titleLabel?.adjustsFontSizeToFitWidth = true
  
          imageCell?.likeButton.enabled = true
  
          if (self.arrayOfDetails.count &gt; indexPath.row) {
              imageCell?.imageText.text = post.text
              imageCell?.imageText.numberOfLines = 0
              imageCell?.imageText.verticalTextAlignmentCenter = true
              imageCell?.imageText.minFontSize = 9
  
              imageCell?.likeButton.setTitle(post.likedBy.count.description, forState: UIControlState.Normal)
  
              imageCell?.commentsButton.setTitle("Comments(\(String(post.comments.count.description)))", forState: UIControlState.Normal)
  
              imageCell?.objectID.append(post.objID)
              imageCell?.uploadedTimeLabel.text = post.CreatedAt.timeAgo
  
              if (post.likedBy.containsObject((PFUser.currentUser()?.username)!!)){
                  imageCell?.likeButton.setBackgroundImage(self.LikeDone, forState: UIControlState.Normal)
              }
              else{
                  imageCell?.likeButton.setBackgroundImage(self.Like, forState: UIControlState.Normal)
              }
  
              imageCell?.imageView.setImageWithUrl(NSURL(string: post.image)!, placeHolderImage: UIImage(named: "Placeholder"))
          }
          return imageCell!
      }
  
      func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -&gt; CGSize {
          return CGSizeMake(UIScreen.mainScreen().bounds.size.width, UIScreen.mainScreen().bounds.size.width+140)
      }
  }
  </code></pre>
  
  <p>And this is my CollectionViewCell.swift:</p>
  
  <pre><code>import UIKit
  import Parse
  import ActiveLabel
  
  class CollectionViewCell: UICollectionViewCell {
  
      @IBOutlet var imageView: UIImageView!
      @IBOutlet var imageText: ActiveLabel!
      @IBOutlet var uploadedTimeLabel: UILabel!
      @IBOutlet var flagContentButton: UIButton!
      @IBOutlet var likeButton: UIButton!
      @IBOutlet var commentsButton: UIButton!
  
      var objectID = [String]()
  }
  </code></pre>
  
  <p>This is how my class in Parse.com looks like:
  <a href="https://i.stack.imgur.com/224kk.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/224kk.jpg" alt="enter image description here"></a></p>
  
  <p>So my question is: Is there any faster or more simple/easy way to get the data from Parse.com, and to my UICollectionView?</p>