It's cool but the pitched syntax is extremely strange.
-
I would not force
newValue
bacause that's not a setter where the value changes. Personally I would prefervalue
orinitialValue
to make it clearer. -
I really don't see why the developer has jump through these unusual syntactic grammar requirements:
struct S {
var readMe: String
var _x: Int
var x: Int {
init(newValue, initializes: _x, accesses: readMe) {
print(readMe)
_x = newValue
}
get { _x }
set { _x = newValue }
}
}
We could rather mimic the set
accessor here.
struct S {
var readMe: String
var _x: Int
var x: Int {
init(initialValue) {
print(readMe) // accesses
self._x = initialValue // initializes
}
get { _x }
set { _x = newValue }
}
}
Just the plain init(initialValue) { ... }
could be sufficient enough. I mean, why can't the compiler not figure out which stored properties are actually being initialized from the init accessor and which are read?
That makes the syntax much simpler and aligned. On top of that the initializes
and accesses
becomes fully transparent.