views:

1483

answers:

3

I'm working through the tutorials in the "Beginning iPhone Development" book. I'm on chapter 4 and I'm getting the following compile error on the "if (segment == kShowSegmentIndex)" line:

error:expected ')' before ';' token

Here's my code:

- (IBAction)toggleShowHide:(id)sender{
    UISegmentedControl *segmentedControl = (UISegmentedControl *)sender;
    NSInteger segment = segmentedControl.selectedSegmentIndex;

    if (segment == kShowSegmentIndex) [switchView setHidden:NO]; 
    else [switchView setHidden:YES];

}

I've compared it with the code in the book several times and have retyped it. Sounds like this error is caused by improper brace placement. Any thoughts?

+1  A: 

Check out this webpage: http://www.iphonedevforums.com/forum/iphone-sdk-development/991-uisegmentcontrol-help.html

It looks like you're not pulling in the definition of kShowSegmentIndex which is defined in a different file that you'll need to include in the class you're working on. Check page 74 of your book.

Jeff Hellman
Thanks. Your comment definitely helped me get the right answer.
Jamis Charles
+3  A: 

Ah I figured it out. The error was in a completely different section. Figures. :)

I wrote "#define kShowSegmentIndex 0;" instead of "#define kShowSegmentIndex 0". Apparently I should have left off the semicolon.

Thanks for the help.

Jamis Charles
That was my guess, dangit! :-) For completeness, you should accept this answer so the question isn't a loose end.
Quinn Taylor
I'm just starting out on Obj-C development, too. This helped me break a day long deadlock. Thanks!-It's always the syntax errors that kill you.
Mark Struzinski
A: 

Got to love google, did a search for "error: expected ')' before ';' token objective-C" and arrived here to discover you had the exact same problem. Thanks :)

Quick resolution.

James

James