swift3.0中,if語句中使用可選型并不支持where這個關(guān)鍵字
var?errorCode:?Int??=?404; var?errorMsg:?String??=?"not?found"; if?let?errorCode?=?errorCode?where?errorCode?==?404, ???let?errorMsg?=?errorMsg{ ????print(errorMsg); }
這樣的代碼在swift3.0里面會報錯,where這個地方會報錯。
那么在swift3.0中如何使用where這個關(guān)鍵字
2016-09-20
where 去掉加上 , 即可
2017-07-05
where 底層會轉(zhuǎn)成if, if where 會加大開銷不推薦。
2016-09-27
確實要加 ? ,
2016-09-20
你說的不完全正確。
各種條件在3.0版本中應(yīng)該用 , 逗號分隔,所以這里去掉where應(yīng)該在前面加上 ?, 逗號
if let errorCode = errorCode , ?errorCode == 404 , let errorMsg = errorMsg { ?}