问题
I'm trying to use localizedCaseInsensitiveContainsString() method introduced in iOS 8:
let match = text.localizedCaseInsensitiveContainsString(searchText)
Swift compiler says:
'String' does not have a member named 'localizedCaseInsensitiveContainsString'
Documentation says:
Swift automatically bridges between the String type and the NSString class.
So, what's going on here?
I know I can use (title as NSString). I just want to know why.
回答1:
I think you still need to cast it to not confuse the compiler I guess:
let match = (text as NSString).localizedCaseInsensitiveContainsString(searchText)
来源:https://stackoverflow.com/questions/26175359/localizedcaseinsensitivecontainsstring-not-available-in-swift