private final class COWBoxImpl : NonObjectiveCBase { var value: T init(_ value: T) { self.value = value #if LOGGING print("new box: \(value)") #endif } } public struct COWBox { private var boxed: COWBoxImpl init(_ value: T) { self.boxed = COWBoxImpl(value) } public var value: T { get { return boxed.value } set { if isUniquelyReferenced(&boxed) { boxed.value = newValue } else { boxed = COWBoxImpl(newValue) } } // FIXME: materializeForSet } } struct COWPoint { private struct Impl { var x: Double var y: Double } private var impl: COWBox init(x: Double, y: Double) { self.impl = COWBox(Impl(x: x, y: y)) } var x: Double { get { return impl.value.x } set { impl.value.x = newValue } } var y: Double { get { return impl.value.y } set { impl.value.y = newValue } } } // Testing var pt = COWPoint(x: 0, y: 0) pt.x = 10 var pt2 = pt pt.x = 20 print(pt.x, pt2.x)