Check for nil with guard instead of if?

前端 未结 4 995
孤独总比滥情好
孤独总比滥情好 2020-12-30 01:48

Is there a guard equivalent of checking if a variable is nil? If so how would I translate a statement like this to use guard instead?<

4条回答
  •  清酒与你
    2020-12-30 02:18

    You can use guards with let.

    guard let preview = post["preview"] else {
       //handle case where the variable is nil
    }
    

提交回复
热议问题