bridgeToObjectiveC not available on Swift Beta 5

2019-06-15 14:20发布

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?

标签: swift ios8
2条回答
Luminary・发光体
2楼-- · 2019-06-15 14:37

try

_bridgeToObjectiveC()

instead of

bridgeToObjectiveC()

as follows:

self.myList.filter{($0 as MyClass).name._bridgeToObjectiveC().localizedCaseInsensitiveContainsString(searchText)}
查看更多
孤傲高冷的网名
3楼-- · 2019-06-15 14:46

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")
查看更多
登录 后发表回答