views:

256

answers:

3

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;
+1  A: 

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];
    ...
}
Eyal Redler
That's great, solved my problem. Thanks for the quick reply,
Maxwell Segal
Maxwell Segal -- if this is the answer hit the checkmark next to it so the system knows the question is answered and so that Eyal Redler will get the credit for it.
TechZen
A: 

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.

Zydeco
Thank you for this and your prompt reply to my questions. Cheers.
Maxwell Segal
A: 

thanks a million times Zydeco. i spent 5 hours just wondering why the values inside my array are getting invalid. after reading this post i realized i am releasing the strings after adding them to the array in my xml parser. i removed the release statement and it worked like a champ.

ammad hussain