Adding sugar for precondition defer

We can trigger defer until after some preconditions like:
guard something
allocate memory; defer {release memory}

What if we want whether to trigger deffer according to the condition and continue execute something,
can we have something like this:

var ok = false
defer if ok {
...
}
...
ok = true //defer code will not execute

this code should has same effects as below

var ok = false
let ok1 = ok
defer {
    if ok1 {
    ...
    }
}
...
ok = true