Mahdi RajaeeJournal
Back to the journalDeveloper tools

Swift deinit can now consume what it owns

SE-0544: allow mutation and consumption of self in non-copyable type deinit.

The change

Previously

A deinit could only borrow its stored properties, never move out of them.

With this change

deinit may now call consuming and mutating methods on stored properties during destruction.

What it means

Teams can call existing cleanup methods from deinit instead of duplicating cleanup code.

My take

Resource cleanup stops being a second implementation of the code you already wrote.

At the source

Swift.orgswift.org