二进制运算符不能应用于int和int类型的操作数?斯威夫特3

前端之家收集整理的这篇文章主要介绍了二进制运算符不能应用于int和int类型的操作数?斯威夫特3前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我是快速的新手,我试了几个小时这个问题.在我的代码下面:
  1. /* [1] error in this line */if filteredCustomReqList != nil {
  2. for i in 0..<filteredCustomReqList?.count {
  3. tempObj = filteredCustomReqList[i] as! [AnyHashable: Any]
  4. bezeichString = tempObj?["bezeich"] as! String
  5.  
  6.  
  7. specialRequestLabel.text = ("\(filteredString),\(bezeichString!)")
  8. print (bezeichString!)
  9. }
  10. }

错误说:

  1. binary operator cannot be applied to operands of type int and int?

其中:

  1. var filteredCustomReqList: [Any]? /* = [Any]() */

如果我使用var filteredCustomReqList:[Any] = [Any]()错误消失但我的if条件总是为真.如何解决此问题?我读过this,但与我的情况不一样(它的int和CGFloat).

任何答案和消息都会对我有所帮助.提前致谢

如果要解包filteredCustomReqList可选变量,可以使用Optional Binding.
  1. var filteredCustomReqList: [Any]?
  2.  
  3. if let filteredCustomReqList = filteredCustomReqList {
  4. for i in 0..<filteredCustomReqList.count {
  5. tempObj = filteredCustomReqList[i] as! [AnyHashable: Any]
  6. bezeichString = tempObj?["bezeich"] as! String
  7.  
  8. specialRequestLabel.text = ("\(filteredString),\(bezeichString!)")
  9. print (bezeichString!)
  10. }
  11. }

猜你在找的Swift相关文章