syntax - Swift - assign local variables based on function parameters -
i have initialization pattern immutable class initializer, of parameters passed in @ creation time.
assigning of internal variables based on - there lot of boiler plate , tend forget things , make errors.
curious if there way assign internal properties in function declaration. there key word (like inout
)?
for instance now:
private var param1 private var param2 private var param3 ... private var paramn init(param1, param2, param3, ..., paramn) { self.param1 = param1 self.param2 = param2 self.param3 = param3 ... self.paramn = paramn }
...would cleaner , less error prone, if there way have function param variable internal instance variable:
init(self.param1, self.param2, ...)
unfortunately, initializer function want generated when no other initializer present, , restricted structs.
i'd recommend filing bug, seems useful feature. keep in mind initializers cannot referenced normal functions (i.e. cannot store them in variables).
Comments
Post a Comment