Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

bridgeToObjectiveC not available on Swift Beta 5

Tags:

swift

ios8

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?

like image 300
Patrick Bassut Avatar asked Aug 05 '14 04:08

Patrick Bassut


2 Answers

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")
like image 122
jstn Avatar answered Oct 10 '22 00:10

jstn


try

_bridgeToObjectiveC()

instead of

bridgeToObjectiveC()

as follows:

self.myList.filter{($0 as MyClass).name._bridgeToObjectiveC().localizedCaseInsensitiveContainsString(searchText)}
like image 37
Timothy B Avatar answered Oct 10 '22 01:10

Timothy B