Expression is not an integer constant expression in iOS objective c -


i want use following expression

-(void)switchcondn{     int expression;     int match1=0;     int match2=1;      switch (expression)      {         case match1:              //statements              break;          case match2:              //statements              break;          default:             // statements              break;      } 

but got

enter image description here

when research found

in order work in objective-c, should define constant either this: #define txt_name 1 or better, this: enum {txt_name = 1}; 

i have been using methods since long time . variable value change in run time need define in others way , didn't want use if else there way of declaration variable others way

i have had study following

why can not use constant in switch - case statement in objective-c ? [error = expression not integer constant expression]

objective c switch statements , named integer constants

objective c global constants case/switch

integer constant 'not reduce integer'

the error expression not integer constant expression means says: in case, value must constant, in, not variable.

you change declarations above switch constants:

const int match1=0; const int match2=1; 

or use enumeration. or #define. can't use non-constant variables there.


Comments

Popular posts from this blog

android - Gradle sync Error:Configuration with name 'default' not found -

java - Andrioid studio start fail: Fatal error initializing 'null' -

html - jQuery UI Sortable - Remove placeholder after item is dropped -