【发布时间】:2023-02-16 18:58:50
【问题描述】:
在我的 KMM 项目中,我有一个方法可以在其中调用 Objective-C predicateWithFormat 方法。当我尝试将传递的字符串文本转换为 NSString 时,我收到警告“此转换永远不会成功”。
override fun elementWithPredicateText(text: String): AppElement {
val predicate = NSPredicate.predicateWithFormat("label CONTAINS %@", text as NSString)
val query = app.descendantsMatchingType(XCUIElementTypeAny).matchingPredicate(predicate)
return UIElementWrapper(query)
}
这里的问题是,如果我不将此字符串转换为 NSString,则会出现构建错误,如下图所示。现在从 String 类型转换为 NSString,构建可能会成功,尽管它有这个恼人的警告,那么我该如何解决这个警告呢?
使用的 iOS 方法。
@kotlin.commonizer.ObjCCallable public open external expect fun predicateWithFormat(predicateFormat: kotlin.String, vararg args: kotlin.Any?): platform.Foundation.NSPredicate { /* compiled code */ }
【问题讨论】:
标签: objective-c kotlin xctest kotlin-multiplatform