On Friday, 19 February 2016 at 21:30:37 UTC, Yuxuan Shui wrote:
I think the same applies to Swift. But I think you're supposed to use it like this:

if let a = var {
  // a is no unwrapped
}

But you would need to give the unwrapped value a new name.


Swift also has guard, which solves this issue.

func ex(a: Int?) {
    // unwrap (possible to add additional check if desired)
    guard let a = a where a > 0 else {
        return // fail
    }

    a.ok // a is now a plain validated Int
}

Reply via email to