我是新手,已经尝试了两个小时了。在我的代码下面:
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条件始终为true。如何获得此修复程序?我已经读过了,但与我的案例(int和CGFloat)并不相同。
var filteredCustomReqList: [Any] = [Any]()
int
CGFloat
任何答案和建议都对我有帮助。提前致谢
您可以使用Optional Binding if let解开filteredCustomReqListOptional变量。
if let
filteredCustomReqList
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!) } }