0

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?

2
  • In your code, match is nothing but an empty dictionary. You don't do anything with your match dictionary at any point after you alloc and init it. If it's in the // do something comment block, please add that. Commented Dec 13, 2011 at 20:52
  • No, I haven't done anything with 'match' indeed. I want 'match' to correspond to the dictionaries from the plist. This must be the problem. I guess I should do something like NSMutableArray *match = [Array..... Any thoughts? Commented Dec 13, 2011 at 21:03

1 Answer 1

1

You need to be adding the individual item from Array inside the date test if statement with the following line:

[matchesToday addObject:[Array objectAtIndex:i]];

At the point that this code executes, match is just an empty mutable array.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.