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 7565073
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T14:03:30+00:00 2026-05-30T14:03:30+00:00

I have some UIPopoverViewControllers that do messaging to delegate UIViewControllers to pass UI events.

  • 0

I have some UIPopoverViewControllers that do messaging to delegate UIViewControllers to pass UI events. Instead of writing a separate method for each event, I have a method in the delegate with a switch statement which determines how to handle the event based on a passed constant (example below).

This is probably poor design but it is what I’ve come up with. I’ve seen this question regarding enums or static classes but didn’t understand the answers.

So..is what I am doing BAD and is there a way I can define the enums in one place so that I don’t have to maintain multiple bits of code that can easily get out of sync?

EDIT Okay, digging around a bit more (here + here) I see that I might be on the right track. So I guess I need to know what and where an implementation file is in iOS.

enum {
kSetPlaybackType = 0,
kSetAllNotesOn,
kSetAllNotesOff,
kSetVelocity,
kSetDuration
};

- (void)barPropertyAction:(int)action withParam:(NSNumber *)param
{
switch (action) {
    case kSetPlaybackType:
        playbackType = [param intValue];
        if (playbackType == kPalindrome){
            palindromeDirection = kPalindromeUp;
        }
        break;

    case kSetAllNotesOn:
        for (BarNote* note in self.barNoteArray) {
            note.noteOn = YES;
        }
        [self.bar updateWindows];
        break;

    case kSetAllNotesOff:
        for (BarNote* note in self.barNoteArray) {
            note.noteOn = NO;
        }
        [self.bar updateWindows];
        break;

    case kSetVelocity:
         for (BarNote* note in self.barNoteArray) {
            note.velocity = [param intValue];
        }
        break;

    case kSetDuration:
        for (BarNote* note in self.barNoteArray) {
            note.duration = [param floatValue];
        }
        break;

    default:
        break;
}
}
  • 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-30T14:03:31+00:00Added an answer on May 30, 2026 at 2:03 pm

    I’m not going to say that your approach is is that bad, but it does have a slight feel to it of the starting embryo of a “god” method – which is a method that tries to do everything. However for the number of choices you have in the code I’d say that its perfectly fine.

    But sharing the enum’s around is very easy. Just put them in their own .h file and import it where it is needed. You can include a .h file as one of the file types under the “C & C++” section.

    The question you referenced was C# based, and one thing they did in that language was to design away the equivalent of .h files, and just use “using” statements to locate the correct symbols. In Objective-C (as in C and C++) you have to do a bit more manual work to achieve the same thing.

    By the way, I would dress the enum up slightly more as:

    typedef enum {
      kSetPlaybackType = 0,
      kSetAllNotesOn,
      kSetAllNotesOff,
      kSetVelocity,
      kSetDuration
    } SetEnumType;
    

    By declaring the enum in a typedef, you gain the ability to declare variables of that type. Ie instead of:

    int varName = kSetAllNotesOn;
    

    You can say:

    SetEnumType varName = kSetAllNotesOn;
    

    This gives extra hints to XCode when presenting you with autocomplete choices, and it makes it semantically better to read as a person, as you know that varName is meant to hold an enum and not just any old number.

    The downside is that you might need to explicitly cast varNum between the enum type and the int type depending on what you are doing.

    However I am not sure if you can declare your method signature as

    - (void)barPropertyAction:(SetEnumType)action withParam:(NSNumber *)param
    

    I am guessing you should be able to (as I think the enum is backed by an int). But if you can’t, then you’d be best doing

    - (void)barPropertyAction:(int)action withParam:(NSNumber *)param
    {
    switch ((SetEnumType)action) {
        case kSetPlaybackType:
            playbackType = [param intValue];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some code that watches the event log for entry written events and
I have some code in jQuery that iterate through children in div using each().
I have some UI in VB 2005 that looks great in XP Style, but
We have some input data that sometimes appears with &nbsp characters on the end.
I have some code like this in a winforms app I was writing to
We have some files on our website that users of our software can download.
Have some data in a sybase image type column that I want to use
I have some code that can convert a single color in a template image
I have some intl characters in a field that django is returning as a
Have some users in Liferay 4.4.2 that are currently active, all having valid passwords.

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.