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)
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With