Tag: switch statement

Can Objective-C switch on NSString?

Is there a more intelligent way to rewrite this? if ([cardName isEqualToString:@”Six”]) { [self setValue:6]; } else if ([cardName isEqualToString:@”Seven”]) { [self setValue:7]; } else if ([cardName isEqualToString:@”Eight”]) { [self setValue:8]; } else if ([cardName isEqualToString:@”Nine”]) { [self setValue:9]; }

Using an NSString in a switch statement

Is it possible to use an NSString in a switch statement? Or is it better to just use if / else if?

Weird Switch error in Obj-C

I have this switch statement in my code: switch(buttonIndex){ case 0: [actionSheet dismissWithClickedButtonIndex:buttonIndex animated:YES]; break; case 1: UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init]; imagePicker.delegate = self; imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera; [self presentModalViewController:[imagePicker autorelease] animated:YES]; break; default: [self openEmailViewInViewController:self]; } And at the UIImagePickerController instantiation in Case 1 I am getting an error: error:expected expression before ‘UIImagePickerController’ […]

Can I declare variables inside an Objective-C switch statement?

I think I’m going blind, because I can’t figure out where the syntax error is in this code: if( cell == nil ) { titledCell = [ [ [ TitledCell alloc ] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier ] autorelease ]; switch( cellNumber ) { case 1: NSString *viewDataKey = @”Name”; etc… When I try to compile it, I’m […]

Declaring variables inside a switch statement

This question already has an answer here: Why can't variables be declared in a switch statement? 23 answers

Tab Bar Controller- switch UIView within one tab

ok here is my applications setup: Two xib’s MainWindow.xib NewsletterView.xib Set up as follows: MainWindow.xib Files owner First Responder The Delegate Window Tab Bar Controller–setup to load tabs from .xib’s Two tabs -Newsletter -Map I’m not concerned about the Map tab. Within the NewsletterView.xib ( i do have the .h and .m files setup) Files […]

NSUserDefault and Switches

I use NSUserDefaults to save a switch on/off and so far it is good. It remembers the switch position in next session. Now to the thing which I do not understand. I use the same switch (with the same name)in another view, let´s say a flip view which is pushed in from the first view. […]

creating constant jump table; xcode; clang; asm

I have quite strange issue when try to create the jump table in my asm program for iphone (arm64): .globl my_func my_func: … //jump (switch) table .L.f_switch: .short .L.case0 – .L.f_switch .short .L.case1 – .L.f_switch … .L.case0: //some case code … .L.case1: //other case code After compilation this table is filled by zeros instead of […]

UIButton as switch

I’m trying to create a push-on-push-off-like button with custom images in Xcode4 for iOS. The code I’m using is – (IBAction)btnAll:(id)sender { UIButton *button = (UIButton *)sender; button.selected = !button.selected; } That works fine for now. But my problem is, that when I’m toggling on, I press it on, then it is popping off again […]

the best way to implement readable switch case with strings in objective-c?

In other dynamic languages like ruby, javascript etc. you can do simply this: switch(someString) { case “foo”: //do something; break; case “bar”: // do something else; break; default: // do something by default; } In objective-c, because it’s derived very colsely from c language, you can’t do that. My best practice for this is: #import […]