XCTAssert syntax error with array shorthand expression and method call
objective-c, xcode, xctest
Solution
`XCTAssert` is a macro with a variable argument list:
#define XCTAssert(expression, format...) \
_XCTPrimitiveAssertTrue(expression, ## format)
In your first form, the preprocessor interprets
[self hasStrings:@[ @"foo", @"bar" ]]
as two macro arguments, separated by a comma.
Problem
So I am diving into unit tests with XCTest, and have run into a little problem. When I write an XCTAssert statement with a shorthand array declaration and method call inside, a syntax error is spat out in Xcode: ``` XCTAssert([self hasStrings:@[ @"foo", @"bar" ]]); ``` In the Xcode compile errors: ``` Expected identifier or '(' ``` However, if I add more brackets around the expression, it will work: ``` XCTAssert(([self hasStrings:@[ @"foo", @"bar" ]])); ``` Is this something to do with some of my syntax not being allowed to be passed into a macro? (Assuming that XCTAssert is a macro)