Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3846954
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T16:28:37+00:00 2026-05-19T16:28:37+00:00

In my app, it finds out the week day in various places and performs

  • 0

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.

  1. 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?
  2. 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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T16:28:38+00:00Added an answer on May 19, 2026 at 4:28 pm

    Following on from Yakuru and the request for more detail:

    typedef enum Days { SUN, MON, TUE, WED, THUR, FRI, SAT, NUMBER_OF_DAYS } Days;
    
    @interface MyClassWithAlarms
    {
       Bool alarms[NUMBER_OF_DAYS];
    }
    
    - (void) setAlarmOnDay:(Days)day;
    
    @end
    
    @implementation MyClassWithAlarms
    
    - (void) setAlarmOnDay:(Days)day
    {
       alarms[day] = YES;
    }
    
    @end
    

    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 Days values.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Currently I have 2 exe files. app.exe and updater.exe. When app.exe finds out that
We have a use case where an app that sends out emails finds a
I'd like to query Windows Media player from an external app to find out
Is there any way to find out or store which app is accessing an
How can i find out if a C# App has been started from the
Is there any way I can find out in my app if the user
Is there any way to (programatically) find out what your app's name is? I'm
I spent a lot of time to find out why my app crashed. My
The question is about Google App Engine Backend. How do I find out the
have an app that finds your GPS location successfully, but I need to be

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.