What I would suggest is simply to pass a TempFile into "doSomething" and through as the closure parameter. If there are reasons why you can't do that, I suggest you add an explicit method to TempFile to remove the item at the URL (what deinit now does) and change deinit to invoke it. (Write the new method so it can be called multiple times but only does the remove once.) Then, at the end of your closure (or wherever in your closure you're done with the file, invoke the explicit method … um … explicitly. At that point, you no longer care when the TempFile is deallocated, so whatever the compiler does with the lifetime is fine.
Your real problem is that you're using an anti-pattern: "deallocation as resource management". This almost never does what you want. (It sort of works in a garbage collected environment, so long as you don't do a lot of resource management very quickly, but it's toxic for reference counted environments.) Moving the removeItem out of deinit avoids the pattern and solves your problem.
>> Where did you get this info btw?
It's always been a major issue in Obj-C because of the interaction with interior pointers such as NSData's "bytes" property. Swift makes the use of interior pointers safe (provided you stay away from types with "Unsafe" in their name), but it keeps this same scope-shortening behavior. AFAIK it's not documented anywhere, but it's necessary (say the compiler writers) to make it possible to free up registers early. That's needed because Intel CPUs have relatively few registers, and having to swap pointers to/from memory kills performance.
Note that this optimization gets by "legally" because of a technicality. The rule that the lifetime of a variable is the entire scope in which it declared isn't actually a rule about the semantics of the object pointed to. Technically, the variable stays in scope even though it doesn't exactly exist after the last reference — the only way you'd prove it wasn't in scope would be to reference it, and if you did that the variable lifetime would be extended as far as the reference.
The idea that the variable lifetime controls the object lifetime absolutely is a fiction that we tell ourselves, which the compiler isn't compelled to go along with.