Sunday 15 August 2010

Lenses into Swift properties -



Lenses into Swift properties -

is there way automatically generate getter/setter function pair property in class in swift? along lines of lens in haskell.

i've been able next manually:

class propertylens<u, t> { allow getter: u -> t allow setter: (u, t) -> () init(getter: (u -> t), setter: ((u, t) -> ())) { self.getter = getter self.setter = setter } func get(u: u) -> t { homecoming getter(u) } func set(u: u, t: t) { setter(u, t) } } // ... allow mypropertylens = propertylens<myclass, int>(getter: { $0.myproperty }, setter: { $0.myproperty = $1 })

however, becomes verbose, tedious, , more error-prone i'd like. there built-in feature i'm missing?

for reply itself, far (1.1) no language build substitute doing (wrapping access process of stored property referenciable object).

for sentiment part of answer, looks code works public variables, nasty break basic encapsulation rules, correct?

swift lenses

No comments:

Post a Comment