0

I have a plist with an array of dictionaries describing events, like this:

<array>
<dict>
    <key>date</key>
    <date>2011-11-19T00:00:00Z</date>
    <key>title</key>
    <string>Nederland - Zweden</string>
</dict>
<dict>
    <key>date</key>
    <date>2011-11-20T00:00:00Z</date>
    <key>title</key>
    <string>Polen - Engeland</string>
</dict>
</array>

Now I have a section in tableview called 'Today' and I want the events that happen today (and only those), to be displayed in that section. I have made strings of today and of the date of the events. Now how can I display only those events that happen today?

Should I start using something like:

if ( [todayString isEqualToString:eventDateString ] ) {
} 

Or start in here (Today-section is 0):

if (section == 0) {
}
user1048042
  • 115
  • 1
  • 1
  • 8

1 Answers1

0

First off, it is generally bad practice to do string comparisons when it can be avoided. You are best off using the NSDate method – timeIntervalSinceNow to get the time between the current time and 12:00am today. If the the event's date is within that range, it is today. Just off the top of my head...but a better answer can be found here.

Also you may want to reconsider testing against the location strings if you are ever filtering by location and if have your app use localization in which for example, we call Spain, Spain. But a Spanish person calls it Espania, etc.

Community
  • 1
  • 1
elusive
  • 460
  • 5
  • 24
  • Yes, as you linked, I would definitely decompose the date into NSDateComponents, then compare those. – joerick Nov 19 '11 at 12:51
  • OK, now I'm using NSDates and I'm comparing them now by using the `isEqualToDate` which seems to work. But how do I get those that are equal in the 'Today' section in tableview? @joerick – user1048042 Nov 19 '11 at 13:39