localizedCaseInsensitiveContainsString not available in Swift

故事扮演 提交于 2019-12-13 01:44:54

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!