0

i have constant for language.At first time when constant value null i want to set a specific value on this constant i write the given below code but its not working correct :

  NSLog(@"Constant value:%@",[Constant getLangCode]);// this print null
  if([[Constant getLangCode] isEqualToString:null])  //this if is not working always goes else 
   {
    NSLog(@"null");
    [Constant updateLangCode:@"en"];
   }
 else
   {
   NSLog(@"null else");
    [Constant updateLangCode:@"en"];
   }

this gives following output:

       constant value:(null)
        null else
Arnab Nandy
  • 6,472
  • 5
  • 44
  • 50
amit gupta
  • 1,167
  • 12
  • 29
  • check this http://stackoverflow.com/questions/5684157/how-to-detect-if-nsstring-is-null/5684166#5684166 – dopcn Sep 14 '14 at 06:29

1 Answers1

1

This can't work. Check whether the value is nil like this

  if([Constant getLangCode] == nil)

or in short

  if(![Constant getLangCode])

But even then your code doesn't make any sense because in both cases you call the same method with the same parameter. Why do you need the if statement?

dasdom
  • 13,975
  • 2
  • 47
  • 58