问题
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