Here is my code:
for (NSManagedObject *object in array) {
if ([[object valueForKey:@"DueDate"] isLessThan:[NSDate date]]) {
count++;
NSLog(@"Looped");
NSString *test = [[NSString alloc] initWithFormat:@"%@", [object valueForKey:@"DueDate"]];
NSLog(@"%@", test);
}
}
NSLog(@"%i", count);
NSDockTile *aTitle = [[NSApplication sharedApplication] dockTile];
[aTitle setBadgeLabel:[NSString stringWithFormat:@"%i", count]];
For some reason this code is adding 8 to the dock icon when it should be 2
On what grounds do you claim that it should be 2? You clearly have eight objects in the array whose due date is less than the current date (which you create a new object for each time through the loop, BTW).
What's the class of the values of these managed objects'
DueDate
property? (Don't look at your model for this—send the due date valuesclass
messages and log the results usingNSLog
.) It's possible that they're not NSDates, and that theircompare:
method is, instead of throwing an exception when asked to compare to an NSDate, simply returning nonsense.Furthermore, why not include this is-less-than-X-date test as the predicate in the fetch request you're using to get these objects? Then (after making sure the due date values are NSDates) you could simply use the
count
of the array. That's assuming you aren't doing something else with the larger result array outside of the code you showed, of course.