In my app, it finds out the week day in various places and performs various tasks. For example:
if ([weekDayString isEqualToString:@"Monday"]) {
mondayAlarm = @"ON";
}
else if ([weekDayString isEqualToString:@"Tuesday"]) {
tuesdayAlarm = @"ON";
}
etc.
And in various places in my code it does the same set of 7 if statements with different outputs. So i have 2 questions about making it less repetitive.
- Is there a way that i could get this down to just the 7 if statements, without repeating each one for each area i want something to happen?
- You’ll notice my variables relating to the weekday all have the weekday in them. Is there any way that i could do this in a smarter way than repeat more or less the same code 7 times?
Help much appreciated.
Thanks.
Following on from Yakuru and the request for more detail:
etc.
You can freely mix C and Objective-C. For an array of just 7 booleans there is no point in using an NSArray, a C array will be much faster and use less memory. You won’t get bounds checking though, so make sure your index is always in range – which it will be if you only use
Daysvalues.