1

Possible Duplicate:
object with the name of a string

I want to call the code below, but be able to change "itemInstance" with a stringe variable. Is this possible?

UIImage *image = [itemInstance getImage:itemNumber];

EDIT: I just read about the NSSelectorFromString method which appears to be what I need to use, but I have no idea how it's supposed to implemented. Any ideas?

3
  • What are you really trying to accomplish? Commented Jun 4, 2012 at 16:30
  • possible duplicate of object with the name of a string, Object name from string Commented Jun 4, 2012 at 17:18
  • @Caleb, I said what I was trying to accomplish in my first sentence... Phillip answered the question. Josh, yes, those do appear to be similar. I didn't see those before. However, I think that the question is still helpful because it is slightly different. Commented Jun 4, 2012 at 18:54

2 Answers 2

3

Not exactly. The simplest way to get that effect is to build a NSDictionary with your strings as the keys and the matching instances as the values. Then it becomes something like:

UIImage *image = [[dict objectForKey:instanceName] getImage:itemNumber];
Sign up to request clarification or add additional context in comments.

2 Comments

Could I use an NSArray instead? I'm going to try that now...
If you can identify the instance in an array, I guess. I picked a dictionary because you said you wanted to select by string.
0

I solved it by selecting the instance from an NSArray. I am selecting Phillips answer though because it got me to where I needed to get.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.