localizedCaseInsensitiveContainsString在Swift中不可用 [英] localizedCaseInsensitiveContainsString not available in Swift
本文介绍了localizedCaseInsensitiveContainsString在Swift中不可用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用iOS 8中引入的 localizedCaseInsensitiveContainsString()
方法:
I'm trying to use localizedCaseInsensitiveContainsString()
method introduced in iOS 8:
let match = text.localizedCaseInsensitiveContainsString(searchText)
快速编译器说:
字符串没有名为 localizedCaseInsensitiveContainsString的成员
'String' does not have a member named 'localizedCaseInsensitiveContainsString'
文档说:
Swift自动在String类型和NSString类之间架桥。
Swift automatically bridges between the String type and the NSString class.
那么,这是怎么回事?
我知道我可以使用(标题为NSString)
。我只是想知道为什么。
I know I can use (title as NSString)
. I just want to know why.
推荐答案
我认为您仍然需要对其进行强制转换,以免混淆我认为的编译器:
I think you still need to cast it to not confuse the compiler I guess:
let match = (text as NSString).localizedCaseInsensitiveContainsString(searchText)
这篇关于localizedCaseInsensitiveContainsString在Swift中不可用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文