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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T04:28:20+00:00 2026-06-10T04:28:20+00:00

Im just wondering whether there is a way (in Objective-C and iPad) to call

  • 0

Im just wondering whether there is a way (in Objective-C and iPad) to call a factory method where I build the name of the object on the fly with a string.

e.g. I have a class XYZ and several factory methods

 +(XYZ *) A;
 +(XYZ *) B;
 +(XYX *) C

I would normally call it like

 [XYZ A];
 [XYZ B];
 [XYZ C];

But I want to be able to call it dynamically with a string e.g.

 NSString *s; 
 ...
 s = @"B";
 [XYZ s];

I hope you get my point.

Thank you.

  • 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-10T04:28:21+00:00Added an answer on June 10, 2026 at 4:28 am

    Yes. You can use NSSelectorFromString() to convert an NSString* into a SEL (which is the same type that @selector() gives you). You can then call this with -performSelector: and its variants.

    [XYZ performSelector:NSSelectorFromString(s)];
    

    -performSelector: is useful for methods that take no arguments and return id or void. -performSelector:withObject: and -performSelector:withObject:withObject: are variants that take 1 or 2 id-typed parameters. If you need more parameters than that, or you need a parameter or return value that isn’t id, then you can use NSInvocation instead to set up the method call. Note that NSInvocation is (relatively) expensive, so it should only be used when there’s no other way.

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

Sidebar

Related Questions

Im just wondering whether there is a way to call a method where i
Just wondering is there any way I can check whether the url links to
Just wondering whether there is a good way to upsert items in a CoreData
I was just wondering whether there is some way to do this: I have
Just wondering whether there is a way to insert a bulk text message into
Just wondering whether there's a way to use turbolinks directly in a rails link_to
just wondering if there is a way to reduce the amount of code needed
Just wondering the best way to replace in place matches on a string. value.replace(bob,
I was wondering whether there's a way of using multiple selectors in jQuery and
This is a silly little thing, but I was just wondering whether there was

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.