1

Hard to get the headline correct since there is so much to tell. I got this NSArray (A portion of it): Mon, 06:00, Radioshow Morning, Mon, 10:00, Lunch radio, 14:00, Afternoon Radio and so on. The NSArray is from an plist in the app.

What I need to build (and failed with) is a search function that shows me the right program with these search values: searchDay and searchTime

Both those values are from NSDate. I've been Googling for about and hour now and hasn't come up with anything usefull so my last hope stands to stackoverflow to show me what I am missing.

I've been dabbling with dateFromString, compare, timeIntervalSinceNow but for some reason failed to achive what I am about to do.

Greatful for any help givven.

TIA Mattias

swe_mattias
  • 621
  • 1
  • 8
  • 15

2 Answers2

1

You should use an NSArray of NSDictionary objects instead of various object types in your NSArray:

NSDictionary *morningShow = [NSDictionary dictionaryWithObjectsAndKeys:@"Mon",@"day","10:00",@"time","morning",@"name",nil];

Then add that to your array. Then, when you are searching, you have a uniform data structure to search inside of.

makdad
  • 6,402
  • 3
  • 31
  • 56
0

I think I have solved it. But I must say I am intrigued by phooze answer.

The way I am doing it now is reading the values (NSString) from the array converting them into an NSDate object and comparing those with timeIntervalSinceDate.

By that I can figure out if currentTime is between two times in the array and such I know what show is on. I've just come up with the solution, the base code is working but the whole code isn't done yet, just on paper/in my mind.

But it feels like a somewhat ugly code... lots of doing small things. But I will pre sue this to the end and if it still looks inefficient and ugly I will look in to other solutions.

swe_mattias
  • 621
  • 1
  • 8
  • 15