objective-c switch case with multiple arguments

Probably a basic question but I would like to reduce some code using multiple arguments on switch case statements. Possible? Correct syntax?

switch (myInteger){
            case (1):   //here I would like to apply multiple arguments as case (1 || 3 || 5)
                <#statements#>
                break;
            case (2):
                <#statements#>
                break;
            default:
                break;

Answers


You can use multiple cases right below each other.

switch (myInteger) {
    case 1:
    case 3:
    case 5:
        // statements
        break;
    case 2:
        // statements
        break;
    default:
        // statements
        break;
}

case 1:
case 3:
case 5:
    statements;
    break;
case 2:
    statements;
    break;
default:
    break;

For Swift 3 there is a modification that I would like to mention

switch some value to consider {
case 1: //single argument
  print("ABC")

case 2,3: // multiple arguments
  print("KLM")

default:
  print("XYZ")
}

Hope it helps you. Thanks


Switch case must declare inside the main method

SYNTAX

Switch (variable r expression)
{ 
   Case 1 : 
     Body ; 
   Break

   Case 2 :
     Body;
   Break;

   Default :
     Body ;
   Break;
}

Need Your Help

Using Maybe type in Haskell

haskell maybe

I'm trying to utilize the Maybe type in Haskell. I have a lookup for key, value tuples that returns a Maybe. How do I access the data that was wrapped by Maybe? For example I want to add the int...

backbone remove view deletes the el

javascript jquery backbone.js backbone-views

I am creating a single page application, and I am quite new to backbone. I have a problem with creating multiple views which uses the same wrapper-div.