Posts

Post marked as solved
3 Replies
1.3k Views
As a swift noob, and coming from C++, I wonder why the following prints 'BOOM!!': var text = "" class ArrayHandle {     var array = Array()     init() {         text = "success"     }     deinit {         text = "BOOM!!"     } } struct Array { var buffer = Buffer() } struct Buffer { func doStuff() { print(text)} } var buffer = ArrayHandle().array.buffer.doStuff() Apparently the deinit is called before the text is printed... When you change the code to: var handle = ArrayHandle() handle.array.buffer.doStuff() it prints the expected 'success' Is there a way to force developers to use a var to store an object, or is that just a hidden bug that may fail in the future?
Posted
by Marleen70.
Last updated
.