In short, I want my tableView to show events (eg. football matches) that are happening Today. Therefore, I want to add those dictionaries that match to a NSMutableArray by use of addObject. I've tried it with this code, but the NSMutableArray does not show anything:
self.Array = [NSMutableArray arrayWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"matches" ofType:@"plist"]];
matchesToday = [[NSMutableArray alloc] init];
match = [[NSMutableDictionary alloc] init];
for (int i=0; i<[Array count]; i++) {
NSDate *datum = [[Array objectAtIndex:i] objectForKey:@"date"];
NSCalendar *cal = [NSCalendar currentCalendar];
NSDateComponents *components = [cal components:(NSEraCalendarUnit|NSYearCalendarUnit|NSMonthCalendarUnit|NSDayCalendarUnit) fromDate:[NSDate date]];
NSDate *today = [cal dateFromComponents:components];
components = [cal components:(NSEraCalendarUnit|NSYearCalendarUnit|NSMonthCalendarUnit|NSDayCalendarUnit) fromDate:datum];
NSDate *otherDate = [cal dateFromComponents:components];
if([today isEqualToDate:otherDate]) {
//do stuff
[matchesToday addObject:match];
NSLog(@"%i, %@", i, otherDate);
NSLog(@"Match is today");
}
else {
NSLog(@"Match is not today");
}
}
NSLog(@"%@", matchesToday);
}
The plist is an array of dictionaries that looks like this:
<array>
<dict>
<key>date</key>
<date>2011-12-13T00:00:00Z</date>
<key>titel</key>
<string>Tilburg - Oss</string>
</dict>
<dict>
<key>date</key>
<date>2011-12-13T00:00:00Z</date>
<key>titel</key>
<string>Amsterdam - Roosendaal</string>
</dict>
</array>
What am I doing wrong?
matchis nothing but an empty dictionary. You don't do anything with yourmatchdictionary at any point after youallocandinitit. If it's in the// do somethingcomment block, please add that.NSMutableArray *match = [Array.....Any thoughts?