I'm a Beginner so please be friendly while explaining, Thanks.
So basically i'm trying to fetch objects made today using createdAt.
let parseQuery = PFQuery(className: "request")
parseQuery.findObjectsInBackgroundWithBlock { (objects, error) -> Void in
if let objects = objects {
for object in objects {
self.reqDates.append(object.createdAt!)
}
}
}
let formatter = NSDateFormatter()
formatter.dateFormat = "yyyy-MM-dd HH:mm"
let formatteddate = formatter.stringFromDate(self.reqDates[indexPath.row])
myCell.reqDate.text = formatteddate
When i do this fetch it shows me all objects with their dates correctly. But how can i display objects of today only not all of them created. I hope i explained good enough.
Request object where createdAt
is greater than today (midnight)
let parseQuery = PFQuery(className: "request")
let cal = NSCalendar(calendarIdentifier: NSCalendarIdentifierGregorian)!
let components = cal.components([.Day , .Month, .Year ], fromDate: NSDate())
let todayDate = cal.dateFromComponents(components)
parseQuery.whereKey("createdAt", greaterThan:todayDate!)
parseQuery.findObjectsInBackgroundWithBlock { (objects, error) -> Void in
if let objects = objects {
for object in objects {
print(object.createdAt)
}
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.