Re: Switch/case with NSString?
Re: Switch/case with NSString?
- Subject: Re: Switch/case with NSString?
- From: Andreas Mayer <email@hidden>
- Date: Wed, 3 Jan 2007 22:02:36 +0100
Am 03.01.2007 um 21:52 Uhr schrieb d2kagw:
I have a selector run after the user enters a string, depending on
the string entered, a series of different processes need to occur,
if I was writing this in a ECMA based language you would expect to
see it like ( this is an example ):
switch ( tAction )
{
case "do homework":
doHomework();
break;
case "bludge":
case "chill":
case "relax":
doRelax();
break;
default:
error("no action set for request");
}
Build a dictionary with the strings as keys and the actions as
objects. Then you do:
NSDictionary *myActions;
//... set up dictionary here
NSString *selectorName = [myActions objectForKey:theAction];
SEL selector = NSSelectorFromString(selectorName);
[self performSelector:selector];
Or something like that (written in Mail). :)
Andreas
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden