在尝试使用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)
但是我无法弄清楚为什么会有所不同。有人可以解释为什么会这样吗?
该XCT...
宏被写入接受格式字符串-字符串本身是可选的(这样写XCTAssertTrue(YES)
是有效的),但必须是常量字符串。无需格式字符串,这就是为什么你不能传递对象到宏观XCTAssertTrue(YES, @"%@", str)
的作品,但是,说,XCTAssertTrue(YES, str)
还是XCTAssertTrue(NO, nil)
不会。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句