<div dir="ltr">I&#39;m doing a RAII sort of thing with an object, and would like to keep it alive until an completion-block is called (asynchronously).<div><br></div><div>Is it sufficient to say &#39;_ = x&#39; in the completion-block to keep a live reference to the object?<div><br></div><div>I was told that the optimiser is free to discard this line, and thus the object could be freed prematurely depending on how the code is compiled. If so, is there an idiomatic way to do this? Or should I just avoid RAII in Swift?</div></div><div><br></div><div>Thanks!<br></div><div>Mike Ferenduros</div></div>