Re: Switch/case with NSString?
Re: Switch/case with NSString?
- Subject: Re: Switch/case with NSString?
- From: Michael Watson <email@hidden>
- Date: Wed, 3 Jan 2007 15:57:47 -0500
Seems awfully specific that the user has to type "do homework". Why
not make this a pop-up button/menu and use tags? Then you could use
switch easily and you don't have to worry about someone not entering
anything, or entering illegal text. Unorganized, typed-in-Mail.app
example concept:
- (IBAction)performTask:(id)sender
{
int task = [sender tag];
switch (task)
{
case 0:
doHomework();
case 1:
chill();
case 2:
relax();
case 3:
chillax();
}
}
On 03 Jan, 2007, at 15:52, d2kagw wrote:
Hi All!
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");
}
On 04/01/2007, at 3:19 AM, Michael Watson wrote:
I'm interested to know what kind of problem d2kagw is attempting
to solve. Can you give us an example of what you're tackling?
--
m-s
On 03 Jan, 2007, at 10:48, John Stiles wrote:
Yup, I was going to suggest something similar. Use an
NSDictionary to do the lookup for you.
Tommy Nordgren wrote:
On 3 jan 2007, at 11.32, d2kagw wrote:
Hi there,
Anyone know if its possible to do a switch statement with a
NSString? or if there's something similar that you could use as
a replacement?
Cheers
Use a (GLOBAL)NSDictionary that maps from NSString to
NSNumber.
NSNumber * switch_code = [myGlobalDictionary objectForKey:
myString];
switch ([switch_code intValue]) {
----
Kine dies, Kinfolk dies, and thus at last yourself
This I know that never dies, how a dead mans deeds are deemed.
-- Elder edda
Tommy Nordgren
email@hidden
_______________________________________________
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:
40blizzard.com
This email sent to email@hidden
_______________________________________________
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:
40bungie.org
This email sent to email@hidden
_______________________________________________
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
_______________________________________________
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