title: Load data from cloudkit into tableView cells but only within the last 72 hours (swift)
body: <p>I have all the code and records set up exactly the way I want too!  You can create a post and it saves the post in a record on cloudKit.  The problem is I would only like to load the data/post made within the last 72 hours.  </p>
  
  <p>How can I implement that within my code? Here is all my code for the tableView:</p>
  
  <pre><code>    class SweetsTableViewController: UITableViewController {
  
  
  
  
  var sweets = [CKRecord]()
  var refresh:UIRefreshControl!
  
  
  
  override func viewDidLoad() {
      super.viewDidLoad()
  
      refresh = UIRefreshControl()
      refresh.attributedTitle = NSAttributedString(string: "Pull to Refresh Page")
      refresh.addTarget(self, action: "loadData", forControlEvents: .ValueChanged)
      self.tableView.addSubview(refresh)
  
      self.tableView.rowHeight = UITableViewAutomaticDimension
      self.tableView.estimatedRowHeight = 1000.0
  
  
  
  
  
      loadData()
  
  }
  
  func loadData () {
      sweets = [CKRecord]()
  
      let publicData = CKContainer.defaultContainer().publicCloudDatabase
      let query = CKQuery(recordType: "Sweet", predicate: NSPredicate(format: "TRUEPREDICATE", argumentArray: nil))
      query.sortDescriptors = [NSSortDescriptor(key: "creationDate", ascending: false)]
      publicData.performQuery(query, inZoneWithID: nil) { (results:[CKRecord]?, error:NSError?) -&gt; Void in
          if let sweets = results {
              self.sweets = sweets
              dispatch_async(dispatch_get_main_queue(), { () -&gt; Void in
                  self.tableView.reloadData()
                  self.tableView.rowHeight = UITableViewAutomaticDimension
                  self.tableView.estimatedRowHeight = 1000.0
                  self.refresh.endRefreshing()
              })
          }
      }
  }
  
  @IBAction func sendSweet(sender: AnyObject) {
  
  
  
      let alert = UIAlertController(title: "New Post", message: "Enter your Post", preferredStyle: .Alert)
      alert.addTextFieldWithConfigurationHandler { (textField:UITextField) -&gt; Void in
          textField.placeholder = "Your Post"
  
      }
  
      alert.addAction(UIAlertAction(title: "Send", style: .Default, handler: { (action:UIAlertAction) -&gt; Void in
          let textField = alert.textFields!.first!
          let defaults = NSUserDefaults.standardUserDefaults()
  
          let label = defaults.objectForKey("label") as? String
  
          if textField.text != "" {
              let newSweet = CKRecord(recordType: "Sweet")
              newSweet["content"] = textField.text
              newSweet["label"] = label
  
              let publicData = CKContainer.defaultContainer().publicCloudDatabase
              publicData.saveRecord(newSweet, completionHandler: { (record:CKRecord?, error:NSError?) -&gt; Void in
                  if error == nil {
                     dispatch_async(dispatch_get_main_queue(), { () -&gt; Void in
                      self.tableView.beginUpdates()
                      self.sweets.insert(newSweet, atIndex: 0)
                      let indexPath = NSIndexPath(forRow: 0, inSection: 0)
                      self.tableView.insertRowsAtIndexPaths([indexPath], withRowAnimation: .Top)
                      self.tableView.rowHeight = UITableViewAutomaticDimension
                      self.tableView.estimatedRowHeight = 1000.0
                      self.tableView.endUpdates()
  
                     })
  
                  }else{
                      print(error)
                  }
              })
          }
      }))
  
      alert.addAction(UIAlertAction(title: "Cancel", style: .Cancel, handler: nil))
  
      self.presentViewController(alert, animated: true, completion: nil)
  
  }
  
  
  override func didReceiveMemoryWarning() {
      super.didReceiveMemoryWarning()
  }
  
  
  
  override func numberOfSectionsInTableView(tableView: UITableView) -&gt; Int {
  
      return 1
  }
  
  override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -&gt; Int {
  
      return sweets.count
  }
  func configureTableView() {
  tableView.rowHeight = UITableViewAutomaticDimension
  tableView.estimatedRowHeight = 1000.0
  }
  
  
  override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -&gt; UITableViewCell {
      let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath)
  
      tableView.rowHeight = UITableViewAutomaticDimension
      tableView.estimatedRowHeight = 1000.0
      cell.textLabel?.sizeToFit()
      cell.textLabel?.numberOfLines = 0
  
  
  
      if sweets.count == 0 {
          return cell
      }
  
  
          let sweet = sweets[indexPath.row]
  
  
      if let sweetContent = sweet["content"] as? String {
  
          let label = sweet["label"] as? String
  
          let dateFormat = NSDateFormatter()
          dateFormat.dateFormat = "- h:mm a"
          let dateString = dateFormat.stringFromDate(sweet.creationDate!)
  
          cell.textLabel?.text = sweetContent
          cell.detailTextLabel?.text = label
  
          tableView.rowHeight = UITableViewAutomaticDimension
          tableView.estimatedRowHeight = 1000.0
  
  
          }
  
      return cell
      }
  
  override func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {
  
  }
  
  override func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -&gt; [UITableViewRowAction]? {
  
      let sweet = sweets[indexPath.row]
  
      if let sweetContent = sweet["content"] as? String {
  
          let label = sweet["label"] as? String
  
          let dateFormat = NSDateFormatter()
          dateFormat.dateFormat = "h:mm a"
          let dateString = dateFormat.stringFromDate(sweet.creationDate!)
  
          var timeAction = UITableViewRowAction(style: .Normal, title: "\(dateString)") { (action: UITableViewRowAction, indexPath: NSIndexPath!) -&gt; Void in
  
              let firstActivityItem = self.sweets[indexPath.row]
  
              let activityViewController = UIActivityViewController(activityItems: [firstActivityItem], applicationActivities: nil)
  
              self.presentViewController(activityViewController, animated: true, completion: nil)
  
      }
          timeAction.backgroundColor = UIColor.grayColor()
  
          return [timeAction]
  
      }
  
      return nil}
  </code></pre>
  
  <p>}</p>