4

i want to set the name of an object like UIButton from a string.

NSString *buttonName = [[NSString alloc] initWithString:@"someString"];

My goal is:

UIButton *someString = [[UIButton buttonWithType:UIButtonTypeCustom]retain];

how can i solve this?

1
  • That doesn't make much sense... your first code sample isn't even valid Objective-C, and it is not really clear what your intention is. A UIButton is no string. Please be more verbose, explain your problem that you want to solve with this "setting name of an object". Commented Oct 8, 2010 at 8:44

1 Answer 1

6

You can't - variable names are resolved by the compiler well before any Objective-C code is executed. What you can do is maintain a map of strings to objects like buttons etc. using NSMutableDictionary:

NSString *string = @"someString";
[buttonMap setObject: [UIButton buttonWithType:UIButtonTypeCustom] forKey: string];

//...time passes...

[[buttonMap objectForKey: @"someString"] setEnabled: YES];
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.