guard statements

Here’s the code if you want to experiment with it:

guard let user = getUser() else {
    throw UserError.noUser
}

guard let address = getAddress(of: user) else {
    throw UserError.noAddress
}

guard let paymentMethod = getPaymentMethod(of: user) else {
    throw UserError.noPaymentMethod
}

// do something
Previous
Previous

lazy + private(set)

Next
Next

concise [weak self]