Reputation: 1624
IU am experienced in Java, but new to Objective C, so this might be very stupid. Nevertheless, I have been struggling for a while now, searching for the reason why I get an expected expression error from the following code.
CGAffineTransform move = CGAffineTransformMakeTranslation(middleX, middleY);
[shapePath applyTransform:move];
[shapePath stroke];
[shapePath fill];
shapePath is a UIBezierPath, middleX and middleY are CFFloats.
The error is a "parse issue", it just says "expected expression", on the first line above
Upvotes: 1
Views: 354
Reputation: 56625
With the extra context that you were using this inside a switch
statement I know what is wrong.
You can't declare variables inside a switch statement without enclosing the cases in curly brackets. You can read about why this is in this answer (in short, they don't introduce new scopes).
For example, creating a variable like this gives the compiler error that you are facing:
but if you add braces around the case (like below) then you can create variables within that scope
There is no problem with the code that you have shown in that question. The following code works for me without any compiler errors:
UIBezierPath *shapePath = [UIBezierPath bezierPath];
CGFloat middleX = 10.0;
CGFloat middleY = 10.0;
CGAffineTransform move = CGAffineTransformMakeTranslation(middleX, middleY);
[shapePath applyTransform:move];
[shapePath stroke];
[shapePath fill];
You should look for other syntax errors in the just above what you have included in your question.
For example, as suggested in this answer, you may be missing a closing bracket (}
) somewhere else in your code.
Upvotes: 1
Reputation: 1624
This code was in a switch clause. When I declared the move variable outside it, it disappeared. Don't know why though. Now it works.
Upvotes: 0