我是新手解析,我需要帮助检索当月的对象。
首先,我有一个名为food
的类,并且有一个名为Date
的{{1}}类型的列
我假设我必须使用更大而且更少,但我不确定如何。
food_date
答案 0 :(得分:0)
我认为你需要这样的东西:
NSCalendar *calendar = [NSCalendar currentCalendar];
NSDateComponents *components = [calendar components:(NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay) fromDate:[NSDate date]];
components.day = 1;
// Get the date of the first day of the current month
NSDate *minimumDate = [calendar dateFromComponents:components];
components.month = components.month + 1;
// Get the date of the first day of the next month
NSDate *maximumDate = [calendar dateFromComponents:components];
PFQuery *foodList = [PFQuery queryWithClassName:@"food"];
[foodList whereKey:@"food_date" greaterThanOrEqualTo:minimumDate];
[foodList whereKey:@"food_date" lessThan:maximumDate];
[foodList findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if (!error) {
// The find succeeded.
NSLog(@"Successfully retrieved %d foods.", objects.count);
// Do something with the found objects
for (PFObject *object in objects) {
NSLog(@"%@", object.objectId);
}
} else {
// Log details of the failure
NSLog(@"Error: %@ %@", error, [error userInfo]);
}
}];
我希望有所帮助。