im attempting to only load posts that were created within 24 hours of the current time. Im having issues with the part where I set NSDate < NSDate, but being that NSDate is not an Int I don't know another way to accomplish the same task. Any help appreciated!
override func viewDidAppear(animated: Bool) {
var annotationQuery = PFQuery(className: "Post")
currentLoc = PFGeoPoint(location: MapViewLocationManager.location)
//annotationQuery.whereKey("Location", nearGeoPoint: currentLoc, withinMiles: 10)
annotationQuery.whereKeyExists("Location")
annotationQuery.findObjectsInBackgroundWithBlock {
(points, error) -> Void in
if error == nil {
// The find succeeded.
println("Successful query for annotations")
// Do something with the found objects
let myPosts = points as! [PFObject]
for post in myPosts {
let point = post["Location"] as! PFGeoPoint
let annotation = MKPointAnnotation()
annotation.coordinate = CLLocationCoordinate2DMake(point.latitude, point.longitude)
annotation.title = post["title"] as! String!
let annotationSubTitleUser = post["username"] as! String!
let formatter = NSDateFormatter()
formatter.dateStyle = NSDateFormatterStyle.ShortStyle
formatter.timeStyle = .ShortStyle
let dateString = formatter.stringFromDate(post.createdAt!)
var current = NSDate()
var expireDate = NSDate(timeIntervalSinceNow: 60 * 60 * 24)
annotation.subtitle = "User: \(annotationSubTitleUser) Time: \(dateString)"
//Here is where I am having issues setting current < expireDate
if (current < expireDate) {
self.mapView.addAnnotation(annotation)
}
}
} else {
// Log details of the failure
println("Error: \(error)")
}
}
}