Reputation: 1747
I have a working application I'm about to distribute and am tidying up NSLog statements in it. When I remove NSLog from from a "case" statement, the NSArray declared within the "case" statement errors as Expected expression before AND undeclared. Anybody any idea why this may be? This is happening on all case statements in my app where I'm now removing NSLog. An example code sections appears below:
switch (chosenScene)
{
case 0:
//NSLog(@"group1"); // the following NSArray errors with "expected expression.." AND "..group1Secondsarray undeclared"
NSArray *group1SecondsArray = [NSArray arrayWithObjects: @"Dummy",@"1/15",@"1/30",@"1/30",@"1/60",@"1/125",@"1/250",nil];
NSArray *group1FStopArray = [NSArray arrayWithObjects: @"Dummy",@"2.8",@"2.8",@"4",@"5.6",@"5.6",@"5.6",nil];
NSString *group1SecondsText = [group1SecondsArray objectAtIndex:slider.value];
calculatedSeconds.text = group1SecondsText;
NSString *group1FStopText = [group1FStopArray objectAtIndex:slider.value];
calculatedFStop.text = group1FStopText;
[group1SecondsText release];
[group1FStopText release];
break;
Upvotes: 2
Views: 580
Reputation: 2966
You don't have to release group1SecondsText
and group1FStopText
, they have a retain count of 1 because they are in the array, if you release them they will become invalid, and when the array is released it will break.
When you access objects in a NSArray with objectAtIndex:
it doesn't increase the retain count, it just returns the object from the array.
Upvotes: 0
Reputation: 438
I don't know the formal explanation but if you're doing anything other then simple assignment or returning a value in the case statement then you need to put it inside brackets.
case 0:
{
NSArray* myArray=[NSArray arrayWithObjects:ob1, obj2,nil];
...
}
Upvotes: 1