我是快速的新手,我试了几个小时这个问题.在我的代码下面:
/* [1] error in this line */if filteredCustomReqList != nil { 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条件总是为真.如何解决此问题?我读过this,但与我的情况不一样(它的int和CGFloat).
任何答案和消息都会对我有所帮助.提前致谢
如果要解包filteredCustomReqList可选变量,可以使用Optional Binding.
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!) } }