user3030104
user3030104

Reputation: 3

iOS error Expected ')'

First I define a value.

#import "ViewController.h"
#define SLIDE_TOP 100;
#define SLIDE_BOTTOM -100;

if(distance > SLIDE_TOP){
    NSLog(@"TOP");
}

I found same errors

1. ViewController.m:98:19: Expected ')' 2. ViewController.m:98:19: If statement has empty body

Upvotes: 0

Views: 881

Answers (2)

Dunes Buggy
Dunes Buggy

Reputation: 1819

Change these

#define SLIDE_TOP 100;
#define SLIDE_BOTTOM -100;

to

#define SLIDE_TOP 100
#define SLIDE_BOTTOM -100

; is not required in define.

Upvotes: 1

Andrew Madsen
Andrew Madsen

Reputation: 21383

When you #define something, the preprocessor simply substitutes replacement tokens (everything after the identifier) for the identifier in the source code. So, your if statement looks like this after the preprocessor runs:

if (distance > 100;) {
    NSLog(@"TOP");
}

Note that the semicolon after "100" is included. The compiler doesn't expect the statement to end there, because there's an unmatched open parenthesis, so it complains that you're missing a ')'. The fix is to remove the semicolon from the end of the #define statement:

#define SLIDE_TOP 100

Upvotes: 3

Related Questions