Getters and Setters Example

suggest change
struct Square {
    private(set) var area = 0

    var side: Int = 0 {
        didSet {
            area = side*side
        }
    }
}

The same pattern on a public type. A public memberwise initializer is not synthesized, so this one is written out:

public struct Square {
    public private(set) var area = 0
    public var side: Int = 0 {
        didSet {
            area = side*side
        }
    }
    public init() {}
}

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents