二元运算符不能应用于 int 和 int 类型的操作数?斯威夫特 3 [英] Binary operator cannot be applied to operands of type int and int? Swift 3
本文介绍了二元运算符不能应用于 int 和 int 类型的操作数?斯威夫特 3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是 swift 新手,我已经尝试了这个问题几个小时.在我的代码下方:
I'm new in swift and I've try this problem for a couple hour. Below my code :
if filteredCustomReqList != nil { /* [1] error in this line */
for i in 0..<filteredCustomReqList?.count {
tempObj = filteredCustomReqList[i] as! [AnyHashable: Any]
bezeichString = tempObj?["bezeich"] as! String
specialRequestLabel.text = ("\(filteredString), \(bezeichString!)")
print (bezeichString!)
}
}
错误说:
binary operator cannot be applied to operands of type int and int?
哪里:
var filteredCustomReqList: [Any]? /* = [Any]() */
如果我使用 var filteredCustomReqList: [Any] = [Any]()
错误消失了,但我的 if 条件始终为真.如何获得此修复程序?我已阅读这个但它与我的情况不同(它的 int
和 CGFloat
).
if i using var filteredCustomReqList: [Any] = [Any]()
the error is gone but my if condition is always true. How to get this fix ? I have read this but its not same with my case (its int
and CGFloat
) .
任何答案和建议都会对我有所帮助.提前致谢
Any answer and sugestion will help for me. Thanks In Advance
推荐答案
您可以使用可选绑定 if let
来解包 filteredCustomReqList
可选变量.
You can use Optional Binding if let
to unwrap filteredCustomReqList
Optional variable.
var filteredCustomReqList: [Any]?
if let filteredCustomReqList = filteredCustomReqList {
for i in 0..<filteredCustomReqList.count {
tempObj = filteredCustomReqList[i] as! [AnyHashable: Any]
bezeichString = tempObj?["bezeich"] as! String
specialRequestLabel.text = ("\(filteredString), \(bezeichString!)")
print (bezeichString!)
}
}
这篇关于二元运算符不能应用于 int 和 int 类型的操作数?斯威夫特 3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文