I'm writing an app that uses bridgeToObjectiveC() on a String object. Since Beta 5 this is no longer available.
我正在编写一个应用程序,它在一个字符串对象上使用bridgeToObjectiveC()。因为测试版5已经没有了。
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?
5的等效代码是什么?
2 个解决方案
#1
16
Use as
to cast to NSString
for the same effect:
用于转换为NSString,以获得同样的效果:
("string" as NSString).localizedCaseInsensitiveCompare("other string")
Or like this with optional chaining:
或者像这样有选择性的链接:
("string" as NSString?)?.localizedCaseInsensitiveCompare("other string")
#2
2
try
试一试
_bridgeToObjectiveC()
_bridgeToObjectiveC()
instead of
而不是
bridgeToObjectiveC()
bridgeToObjectiveC()
as follows:
如下:
self.myList.filter{($0 as MyClass).name._bridgeToObjectiveC().localizedCaseInsensitiveContainsString(searchText)}
#1
16
Use as
to cast to NSString
for the same effect:
用于转换为NSString,以获得同样的效果:
("string" as NSString).localizedCaseInsensitiveCompare("other string")
Or like this with optional chaining:
或者像这样有选择性的链接:
("string" as NSString?)?.localizedCaseInsensitiveCompare("other string")
#2
2
try
试一试
_bridgeToObjectiveC()
_bridgeToObjectiveC()
instead of
而不是
bridgeToObjectiveC()
bridgeToObjectiveC()
as follows:
如下:
self.myList.filter{($0 as MyClass).name._bridgeToObjectiveC().localizedCaseInsensitiveContainsString(searchText)}