【问题标题】:cannot invoke '!=' with an argument list of type (@lvalue Bool, ($T5))不能使用类型参数列表调用 '!=' (@lvalue Bool, ($T5))
【发布时间】:2015-01-10 07:43:53
【问题描述】:

标题是我在编译这段代码sn-p@line3时得到的错误信息:

var categoryMatch = (scope == "All") || (candy.category == scope)
var stringMatch = candy.name.rangeOfString(searchText)
return categoryMatch && (stringMatch != nil);

这里有什么问题?

谢谢

【问题讨论】:

    标签: xcode swift nsstring nsrange


    【解决方案1】:

    问题是rangeOfString: 返回的NSRange 不能等同于nil。而不是检查NSRangelocation 属性。

    您需要更改您的退货声明,例如:

    return categoryMatch && (stringMatch.location != NSNotFound)
    

    参考资料:

    【讨论】:

      【解决方案2】:

      我猜函数的返回类型不仅仅是Bool

      categoryMatch && (stringMatch != nil) 创建一个 Bool 值。

      也许你的函数返回类型是一个 (Bool,Bool) 的元组。 那么你正确的返回值应该是这样的

      return (categoryMatch , (stringMatch != nil))
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2020-08-23
        • 2021-04-07
        • 1970-01-01
        • 2021-10-16
        • 2021-10-10
        • 1970-01-01
        • 2021-08-19
        • 1970-01-01
        相关资源
        最近更新 更多