The example in Deinitialization chapter no longer compiles

The following

class Bank {
    static var coinsInBank = 10_000
    static func distribute(coins numberOfCoinsRequested: Int) -> Int {
        let numberOfCoinsToVend = min(numberOfCoinsRequested, coinsInBank)
        coinsInBank -= numberOfCoinsToVend
        return numberOfCoinsToVend
    }
    static func receive(coins: Int) {
        coinsInBank += coins
    }
}

no longer compiles and fails with error: static property 'coinsInBank' is not concurrency-safe because it is nonisolated global shared mutable state compilation error.


PS: It would be nice to correct this phrasing as well:

A deinitializer is called immediately before a class instance is deallocated. You write deinitializers with the deinit keyword, similar to how initializers are written with the init keyword. Deinitializers are only available on class types.

since deinitializers available for ~Copyable as well (in general, it would be better if copyable and related features were discusssed in the language guide and not only in the language reference part, but at least a link to ~Copyable should be given here).

3 Likes

Thank you for opening the issue in GitHub!