是否有一个适用于Swift代码的流畅匹配API?主要的目标-C匹配者候选人似乎是OCHamcrest和期望值,两者都依赖于复杂的宏,而(按照医生的说法)并不适用于Swift代码。
#define HC_assertThat(actual, matcher) \
HC_assertThatWithLocation(self, actual, matcher, __FILE__, __LINE__)(OCHamcrest)
#define EXP_expect(actual) _EXP_expect(self, __LINE__, __FILE__, ^id{ return EXPObjectify((actual)); })(预期)
是否还有另一种适用于Swift的方法,或者用某种方式将其中的一种或另一种包装起来,以便它们可以与Swift一起使用?
ETA:面向未来读者的 --我看了SwiftHamcrest (per 乔恩·里德的回答),但目前我已经决定使用快速/敏捷了。
发布于 2014-10-19 05:42:11
https://github.com/nschum/SwiftHamcrest是Hamcrest的一个快速的本机实现。
发布于 2014-10-09 20:37:25
复杂的预处理器宏不会被转换成Swift的替代品。苹果有一个讨论Swift,在其中,他们描述了如何使断言函数的博客。
第一个宏很容易变成Swift函数
#define HC_assertThat(actual, matcher) \
HC_assertThatWithLocation(self, actual, matcher, __FILE__, __LINE__)在Swift:
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)); })在Swift:
func EXP_expect(caller: AnyObject, actual: String, line: UWord = __LINE__, file: String = __FILE__) {
_EXP_expect(caller, Int32(line), file.fileSystemRepresentation, ({
return EXPObjectify(caller)
})
}请注意,我在猜测您希望传递给预处理器函数的内容。
https://stackoverflow.com/questions/24480964
复制相似问题