在尝试使用 XCTest 测试我的应用程序时,执行以下操作时出现构建错误:
#import <XCTest/XCTest.h>
@interface MyTests : XCTestCase
@end
@implementation MyTests
- (void)testExample
{
NSString *str = @"foo";
XCTAssertTrue(YES, str); // Parse issue: Expected ')'
}
@end
但如果我这样做,我不会收到构建错误:
#import <XCTest/XCTest.h>
@interface MyTests : XCTestCase
@end
@implementation MyTests
- (void)testExample
{
XCTAssertTrue(YES, @"foo"); // this is just fine...
}
@end
我得到的构建错误是:
Parse issue: Expected ')'
它在“str”中的“s”下放了一个箭头。
我发现我可以通过改变来解决这个问题
XCTAssertTrue(YES, str)
到
XCTAssertTrue(YES, @"%@", str)
但我就是不明白为什么会有所作为。有人可以解释为什么会这样吗?