With an empty body, you mean?

> On 30 Jun 2017, at 22:00, Joe Groff <jgr...@apple.com> wrote:
> 
> 
>> On Jun 30, 2017, at 11:47 AM, Mike Ferenduros via swift-users 
>> <swift-users@swift.org> wrote:
>> 
>> I'm doing a RAII sort of thing with an object, and would like to keep it 
>> alive until an completion-block is called (asynchronously).
>> 
>> Is it sufficient to say '_ = x' in the completion-block to keep a live 
>> reference to the object?
>> 
>> 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?
> 
> `withExtendedLifetime(x) { ... }` is the supported way of extending the 
> lifetime of an object.
> 
> -Joe
_______________________________________________
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users

Reply via email to