2

I have one method in which there is one condition which checks the bool value and do some task based on the condition. It is working perfectly in the debug build but in the release build the bool value always return true.

Below is sample code of the method which is behaving differently in debug and release version.

-(void)addNotification:(NSMutableDictionary *)dictNotificationData
{
   BOOL addNotification;

    if ([[dictNotificationData objectForKey:@"id"] integerValue] == 2) {
        if ([[dictNotificationData objectForKey:@"isActive"] boolValue]) {
            addNotification = YES;
        }
    }
    else {
        addNotification = NO;
    }

//In the release version this value always return true eventhough it is going in the else part.
   if (addNotification) { 
      //code for local notification
   }
}

Please let me know if any one has any idea about why it is behaving differently in debug and release version.

Dipesh Patel
  • 122
  • 4
  • can you explain your question brief? It is still need more information. – Wos Apr 13 '17 at 12:20
  • 1
    `if ([[dictNotificationData objectForKey:@"id"] integerValue] == 2) { if ([[dictNotificationData objectForKey:@"isActive"] boolValue]) {` so your problem is that those two statements are always `true` in release and not always in debug. Did you try tracking those values ? – Rafalon Apr 13 '17 at 12:21

4 Answers4

1

Actually I found the solution for that. The Bool local variable always initialised as garbage value if we do not provide any which was creating the problem in my case. When I initialised BOOL addNotification = NO; it works fine.

Found the answer here. Default value of BOOL

Thanks All.

Community
  • 1
  • 1
Dipesh Patel
  • 122
  • 4
0

Not the question that you are asking but in your code is it possible that addNotification is tested before it is initialised - if the second 'if' is false.

Ross
  • 1
  • 1
  • 1
0

For boolValue check please try this

NSNumber * isSuccessNumber = (NSNumber *)[response objectForKey: @"success"];

if([isSuccessNumber boolValue] == YES) {

} else {

}

Community
  • 1
  • 1
Vinay Kumar
  • 107
  • 1
  • 12
0

Boolen value can be changed on the device version. So what the result for this line, if this line return 0 or 1, can be change the result. [dictNotificationData objectForKey:@"isActive"]

For instance, run your code on both 32-bit iOS and 64-bit iOS. It should correctly display “Different” on one, but not the other.

if (different(1, 2)) {
    NSLog(@"Different!");
} else {
    NSLog(@"Not different.");
}
Emre Gürses
  • 1,992
  • 1
  • 23
  • 28