Weird "Expected expression" error

Discussion in 'iOS Programming' started by moonman239, Jan 9, 2015.

  1. moonman239, Jan 9, 2015
    Last edited: Jan 9, 2015

    moonman239 macrumors 68000

    Mar 27, 2009
    As indicated in the code below, what I'm trying to do is access a table view cell from within a switch-case statement. The line where I do that is bolded below. Note that the bolded line of code works if I move it out of the switch-case statement, and no other errors are generated. I tried cleaning the project, but to no avail.
    -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
        NSString *segueIdentifier;
        NSInteger row = [indexPath row];
        NSInteger section = [indexPath section];
        if (section < [[self elements] count] - 1)
        switch (row) {
            case 0:
                [B]UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];[/B] 
                segueIdentifier = @"VCSegue1";
            case 1:
                segueIdentifier = @"VCSegue3";
            segueIdentifier = @"VCSegue4";
        [self performSegueWithIdentifier:segueIdentifier sender:[NSNumber numberWithInteger:[indexPath section]]];
  2. subsonix macrumors 68040

    Feb 2, 2008
    You can not declare variables inside a switch statement, the scope would also make "cell" invisible outside the switch even if it was allowed.
  3. mfram macrumors 65816

    Jan 23, 2010
    San Diego, CA USA
    Or you could put everything under the case 0 statement in a block. That is, put braces around it. Then you could declare a new variable. But, again, it would only have scope within that block.
  4. moonman239 thread starter macrumors 68000

    Mar 27, 2009
    That's weird, but OK. Although, a "you can't put that there" message in Xcode would've been nice.
    I think I'll do that.

Share This Page