As some people have already answered, you can use let
guard let preview = post["preview"] else { /* Handle nil case */ return }
If you are not using a variable, you can use the underscore to not declare the variable and avoid the warning.
guard let _ = post["preview"] else { /* Handle nil case */ return }
You can also do regular boolean check instead of using let
guard post["preview"] != nil else { return }
More general case for boolean checking on a guard
guard conditionYouExpectToBeTrue else { /* Handle nil case */ return }
If you want to be able to change the variable, you can use var instead of let
guard var preview = post["preview"] else { return }
Swift 3.0
You can combine var/let with logical validation using commas between statements.
guard let preview = post["preview"], preview != "No Preview" else { /* Handle nil case */ return }
Swift 2.x
You can combine var/let with boolean checking using where
guard let preview = post["preview"] where preview != "No Preview" else { /* Handle nil case */ return }
source share