Using NSString initWithFormat:
option within an XCTAssertEqualObjects
directly will given an error.
XCTAssertEqualObjects([[NSString alloc] initWithFormat:@"Hello %@", @"world"], @"Hello world");
This will show error in Xcode like:
@try statement without a @catch and @finally clause
Expected ']'
Expected identifier or '('
Expected identifier or '('
Extraneous closing brace ('}')
Unexpected '@' in program
This is because the XCTAssertEqualObjects
is a macro and it accepts va_args
and initWithFormat:
also accepts va_args
. So there is a conflict and we need to wrap it within a parentheses.
XCTAssertEqualObjects(([[NSString alloc] initWithFormat:@"Hello %@", @"world"]), @"Hello world");