Sal*_*ler 2 nspredicate ios swift
我有这个错误: XCTAssertTrue failed: throwing "[<XCElementSnapshot 0x7fea978b1a10> valueForUndefinedKey:]: this class is not key value coding-compliant for the key staticTexts."
这是代码:
let predicate = NSPredicate(format: "(self.staticTexts[%@].exists == true) AND (self.staticTexts[%@].exists == true)", message, nameString)
XCTAssert(app.collectionViews.childrenMatchingType(.Cell).elementMatchingPredicate(predicate).exists)
Run Code Online (Sandbox Code Playgroud)
第二行抛出错误。
我已经看过关于 SO 的其他答案,但也有同样的错误,这主要是由具有不同类的变量引起的,但是我在这里看不到出现此错误的可能性。另外,我检查了谓词的格式是否正确。
我怎样才能摆脱这个错误?
确保您的staticTexts属性dynamic对 objc 可用或以其他方式可用(@objc例如通过标记它)。Swift 不会生成 KVC 兼容的访问器,除非它认为它需要。
或者,使用NSPredicate此处以外的其他内容。在不需要时使属性动态化会产生性能成本,这就是 Swift 不会自动执行的原因。所以标记它dynamic以便单元测试可以访问它可能是一个糟糕的权衡。
| 归档时间: |
|
| 查看次数: |
1220 次 |
| 最近记录: |