我知道这个问题已经用其他各种符号代替了'>'符号问过。但是他们都没有解决我的问题。我需要做的是检查搜索字符串的长度是否大于2,如果是,则执行搜索。为此,我写了以下if
条件:
if countElements(searchString) > 2 {}
其中searchString是String
对象。但是这一行会产生错误:
Could not find an overload for '>' that accepts the supplied arguments
我发现Swift不会隐式转换值,所以我尝试了以下代码,
if Int(countElements(searchString)) > 2 {}
仍然导致同样的问题。这是怎么了
编辑
searchString来自此委托:
func searchDisplayController(controller: UISearchDisplayController!, shouldReloadTableForSearchString searchString: String!) -> Bool {
if countElements(searchString) > 2
{
}
return false
}
我修好了它。实际的问题是迅速如何获取变量。searchString
解决问题后,添加感叹号。更正的代码:
func searchDisplayController(controller: UISearchDisplayController!, shouldReloadTableForSearchString searchString: String!) -> Bool {
if countElements(searchString!) > 2
{
}
return false
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句