bridgeToObjectiveC not available on Swift Beta 5

爷,独闯天下 提交于 2019-12-23 07:11:48

问题


I'm writing an app that uses bridgeToObjectiveC() on a String object. Since Beta 5 this is no longer available.

I'm trying to do this:

self.myList.filter{($0 as MyClass).name.bridgeToObjectiveC().localizedCaseInsensitiveContainsString(searchText)}

Which gives me the error:

'String' does not have a member named 'bridgeToObjectiveC'

What is the equivalent code in Beta 5?


回答1:


Use as to cast to NSString for the same effect:

("string" as NSString).localizedCaseInsensitiveCompare("other string")

Or like this with optional chaining:

("string" as NSString?)?.localizedCaseInsensitiveCompare("other string")



回答2:


try

_bridgeToObjectiveC()

instead of

bridgeToObjectiveC()

as follows:

self.myList.filter{($0 as MyClass).name._bridgeToObjectiveC().localizedCaseInsensitiveContainsString(searchText)}


来源:https://stackoverflow.com/questions/25131122/bridgetoobjectivec-not-available-on-swift-beta-5

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!