The Swift Programming Language guide has the following example:
class Person {
let name: String
init(name: String) { self.name = name }
var apar
john
is an optional var
and it can contain a nil
value. To ensure that the value isn't nil use a !
at the end of the var
name.
From documentation
“Once you’re sure that the optional does contain a value, you can access its underlying value by adding an exclamation mark (!) to the end of the optional’s name. The exclamation mark effectively says, “I know that this optional definitely has a value; please use it.”
Another way to check non nil value is (optional unwrapping)
if let j = json {
// do something with j
}