【发布时间】:2014-08-25 16:00:34
【问题描述】:
我知道这个问题已经用各种其他符号代替了我的例子中的“>”符号。但他们都没有解决我的问题。我需要做的是检查搜索字符串的长度是否大于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
}
【问题讨论】:
-
你试过这个吗:
if countElements(searchString) > Int(2) {}? -
同样的问题。已经试过了
标签: if-statement swift conditional-operator