Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

using XCTAssertEqual with NSString as error message argument

This is an example of how I would use XCTAssertEqual

XCTAssertEqual(valueA, valueB, @"message");

However, when I try the following

NSString *message = @"message";
XCTAssertEqual(valueA, valueB, message);

I get a compiler error, namely,

Expected ')'

It seems like I am simply passing an NSString either way. When i dig into the definition I find

#define XCTAssertEqual(a1, a2, format...) _XCTPrimitiveAssertEqual(a1, a2, ## format)

Which I cannot make heads or tails of. Why am I unable to pass an NSString* as the format... argument into XCTAssertEquals, when it accepts NSString literals like @"message"?

Note: This appears to be the case for all the assertions.

like image 270
CodeWarrior Avatar asked Aug 07 '14 16:08

CodeWarrior


1 Answers

Try this:

XCTAssertEqual(valueA, valueB, @"%@", message);
like image 90
Dan Avatar answered Nov 15 '22 07:11

Dan