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

  • Home
  • SEARCH
  • 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 3595910
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T19:54:53+00:00 2026-05-18T19:54:53+00:00

Newbie question here. I’d like to be able to specify through data (i.e. an

  • 0

Newbie question here. I’d like to be able to specify through data (i.e. an XML file), the appropriate Objective-C message to send. Any advice on if this is possible or how I can do this?

The next best thing, if I can’t do this, would be some way to create a map object that would correlate a key (an int) with a function (I guess also a selector). Is that possible if the above isn’t?

If someone could point me to some tutorial or example code as reference, that’d be great. Right now I’m doing things with a big switch statement, and I don’t like it. (I’m switching on the id and in each case, explicitly calling the method relevant to the particular id.)

  • 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-18T19:54:54+00:00Added an answer on May 18, 2026 at 7:54 pm

    I love that you asked this question; too often, I see Satan’s Swollen Switch Statement. It’s nice to see someone wanting to using a function-table instead.

    If you’re OK with using a property list file (which is usually encoded in XML), this is really easy.

    Just make a property list where the root element is a dictionary, which maps from some keys to some selectors.

    Key               Type         Value
    ----------------------------------------------
    Root              Dictionary
      firstKey        String       someSelector
      secondKey       String       anotherSelector
    

    Load the contents of your property list into an NSDictionary:

    id path = [[NSBundle mainBundle] pathForResource:@"filename" ofType:@"plist"];
    id dict = [NSDictionary dictionaryWithContentsOfFile:path];
    
    SEL selector = NSSelectorFromString([dict objectForKey:@"firstKey"]);
    if ([someObject respondsToSelector:selector]) {
        [someObject performSelector:selector];
    }
    

    Of course, you’ll want to refactor this logic into an appropriate method, and probably cache the property list as an instance variable.

    Note: I personally think it’s better to just put this function table inline; property lists are cool, but I’m not sure that it is very helpful in this case. Also, if you are cool with using Objective-C++, std::map will allow you to get away with not wrapping and unwrapping the selectors in NSString objects, etc.

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

Sidebar

Related Questions

a newbie question here... I've created an entity data model (.edmx) file in one
NEWBIE logger question here: What's the best way to log output to a development
Here goes newbie question number 5, but I don't have a teacher.. so.. anyhow
Sorry in advance for a potentially dumb newbie question, but here goes. I am
I am new in Java so it will be a newbie question, here it
Newbie question on Rails 3 development. I am creating my first app and planning
This is a totally newbie question. I'm running Eclipse on Ubuntu. I created a
Please pardon the newbie question, but I'm stumped. I'm a teacher converting a Rails
Another .net newbie question I created a class that inherits System.Web.UI.Page with the intention
Sorry this is a very newbie question. We have this massive application I am

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.