i have the following code in my application:
NSArray *lstAttributes = [conditionAttribute componentsSeparatedByString:cstrSystemUIConfigurationAttributeConditionSeparator],
*lstValues = [conditionValue componentsSeparatedByString:cstrSystemUIConfigurationAttributeConditionSeparator],
*lstValueTypes = [conditionValueType componentsSeparatedByString:cstrSystemUIConfigurationAttributeConditionSeparator];
if([lstAttributes count] != [lstValues count] ||
[lstAttributes count] != [lstValueTypes count]) return NO;
BOOL bResult = YES;
NSLog(@"attributes amount - %u", [lstAttributes count]);
for(uint i = 0; i < [lstAttributes count]; i ++)
{
NSLog(@"counter: %u", i);
SystemUIConfigurationAttributeCondition *condition = [SystemUIConfigurationAttributeCondition new];
condition.conditionAttribute = [lstAttributes objectAtIndex:i];
condition.conditionValue = [lstValues objectAtIndex:i];
condition.conditionValueType = [lstValueTypes objectAtIndex:i];
bResult &= [self checkCondition:condition forOwner:owner];
FreeObject(&condition);
if(!bResult) break;
}
return bResult;
everything is fine in “debug” configuration. but once i switch it to “release” i face the endless loop. console shows me the following: attributes amount – 2, counter: 0, counter: 1, counter: 1, counter: 1, counter: 1, counter: 1, counter: 1, …… etc.
i tried to use different “for” and “while” operators, but nothing of that worked correctly. the loop still can’t be stopped.
has anyone faced the same problem before?
workaround for this bug as promised:
at first i tried to use code blocks to enumerate all objects in a list instead of “for” loop.
but i got a crash on second iteration. “lstValues” and “lstValueTypes” pointers suddenly changed their values and application received EXC_BAD_ACCESS. possibly usage of 3 arrays while enumerating only 1 of them is not a good idea. debugger shows that enumeration is performed on the same thread, but 2 of 3 arrays are corrupted by the moment of 2nd iteration.
so i decided to split up my initial loop into 2 parts:
first is a usual “for” loop, second – ‘enumerateObjectsUsingBlock:” method of NSArray class. so the final code looks like:
this code works.
i would appreciate if anyone can explain the behavior of my initial loop.