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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T16:59:12+00:00 2026-06-12T16:59:12+00:00

I have a situation, where i load a facebook feed,and depending upon the post

  • 0

I have a situation, where i load a facebook feed,and depending upon the post type (video/image/link etc), i create corresponding classes. Each post type has a different corresponding model class and view class, however there is only one controller class which is instantiated for each post.
Now i need a way of dynamically deciding which model and view classes to create inside the controller for a particular post type. Right now, i have a creation helper class, which returns the corresponding model and view classes depending upon the post type. But it seems like a messy way of doing things. If have 20 something post types, thats 20 something if statements.

Is there a better way of doing this ?

  • 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-06-12T16:59:13+00:00Added an answer on June 12, 2026 at 4:59 pm

    You could keep a map (of sorts) of the post types against the classname used to handle the types:

    static struct
    {
        PostType type;         // A typedef'd enum with POST_TYPE_ONE, ...
        NSString *classname;
    } _handlers[] = 
    {
        { POST_TYPE_ONE, @"OneHandler" },
        { POST_TYPE_TWO, @"TwoHandler" },
        ....
        { POST_TYPE_TWENTY, @"TwentyHandler" }
    };
    
    const NSUInteger NUM_HANDLERS = sizeof(_handlers) / sizeof(_handlers[0]);
    

    And then instantiate the class instance using:

    id handler = nil;
    for (NSUInteger index = 0; index < NUM_HANDLERS && handler == nil; index++)
    {
        if (postType == _handlers[index].postType)
        {
            handler = [[ NSClassFromString(_handlers[index].classname) alloc ] init];
        }
    }
    

    Or if you can guarantee that postType will always be between 0 and 19, can just keep an array of classnames and use:

    id handler = [[ NSClassFromString(_handlers[postType] alloc ] init];
    

    You should ensure all handler classes derive from a common base class, to provide common functionality.

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

Sidebar

Related Questions

I have a situation where I need to ignore parts of page load sub
I have a question about jQuery load best practice. Imagine the following situation: $(#div).on('click',
I have a situation: I upload user controls in a webapp and then load
I have a situation where I load several usercontrols dynamically. Since all of them
I have a situation where pressing F5 or CTRL+R causes a frameset to load
I have a situation where i load all tables from legacy database. but it
I have a situation where i need to load a page based on a
Let's say I have a situation like so: $(window).load(function() { $(body).append(<div id='container'></div>); var i=1;
Original Question I have this situation: type X1 = Class protected oMyList: TMyList; public
I have a situation where I need to dynamically load a URL prefix. I

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.