iOS/Mac OS与Swift配合使用的流畅匹配框架?
是否有一个适用于Swift代码的流畅匹配API?领先的Objective-C匹配器候选对象似乎是OCHamcrest和Expecta,它们都依赖于Swift代码无法使用的复杂宏()iOS/Mac OS与Swift配合使用的流畅匹配框架?,swift,matcher,ochamcrest,expecta,Swift,Matcher,Ochamcrest,Expecta,是否有一个适用于Swift代码的流畅匹配API?领先的Objective-C匹配器候选对象似乎是OCHamcrest和Expecta,它们都依赖于Swift代码无法使用的复杂宏() #define HC_assertThat(actual, matcher) \ HC_assertThatWithLocation(self, actual, matcher, __FILE__, __LINE__) (奥恰姆克雷斯特) (a) 是否有另一种方法可用于Swift,或者以某种方式包装其中一
#define HC_assertThat(actual, matcher) \
HC_assertThatWithLocation(self, actual, matcher, __FILE__, __LINE__)
(奥恰姆克雷斯特)
(a)
是否有另一种方法可用于Swift,或者以某种方式包装其中一种,以便与Swift一起使用
ETA:面向未来读者——我查看了(per),但目前我已确定。复杂的预处理器宏不会转换为它们的Swift替代方案。苹果有一个讨论Swift的博客 第一个宏很容易生成Swift函数
#define HC_assertThat(actual, matcher) \
HC_assertThatWithLocation(self, actual, matcher, __FILE__, __LINE__)
迅速:
func HC_assertThat(caller: AnyObject, actual: String, matcher: String, file: String = __FILE__, line: UWord = __LINE__) {
HC_assertThatWithLocation(caller, actual, matcher, file.fileSystemRepresentation, Int32(line))
}
#define EXP_expect(actual) _EXP_expect(self, __LINE__, __FILE__, ^id{ return EXPObjectify((actual)); })
func EXP_expect(caller: AnyObject, actual: String, line: UWord = __LINE__, file: String = __FILE__) {
_EXP_expect(caller, Int32(line), file.fileSystemRepresentation, ({
return EXPObjectify(caller)
})
}
迅速:
func HC_assertThat(caller: AnyObject, actual: String, matcher: String, file: String = __FILE__, line: UWord = __LINE__) {
HC_assertThatWithLocation(caller, actual, matcher, file.fileSystemRepresentation, Int32(line))
}
#define EXP_expect(actual) _EXP_expect(self, __LINE__, __FILE__, ^id{ return EXPObjectify((actual)); })
func EXP_expect(caller: AnyObject, actual: String, line: UWord = __LINE__, file: String = __FILE__) {
_EXP_expect(caller, Int32(line), file.fileSystemRepresentation, ({
return EXPObjectify(caller)
})
}
请注意,我正在猜测您希望传递给预处理器函数的内容。是Hamcrest的Swift本机实现,出于某些原因,在Swift中可以调用expect,但EXPObjectify和EXPObjectify不可见。我可以在objective-c标题中看到它们的声明,并且我已经将其导入到桥接标题中,但是运气不好。知道如何让它工作吗?