Where is Swift heading for?

Hello, @Alex_Martini

Your understanding is correct.

The phrase mutating get at first looked quite mind rattling to me, it then dawned on me that a get is really a fancy method that takes no arguments and so it can bemutating.

struct Counter {
    private(set) var value: Int = 0

    mutating func nextValue () -> Int {
        value += 1
        return value
    }
}
struct FancyCounter {
    private(set) var value: Int = 0
    
    var nextValue: Int {
        mutating get {
            value += 1
            return value
        }
    }
}

I have just learned about this only a few days ago, when I was reading this discussion: ~Escapable, Span, Ownership Annotations, etc.

I was naively relying on TSPL as the source of truth, despite knowing that it was lagging way behind the current state of Swift. :slight_smile:

2 Likes