Pass Object Variables Directly to init
Posted: Sat Jan 04, 2014 5:10 pm
What if we could replace this:
With this:
Less typing . There are many cases where the only reason you even need to write an init is to assign values to object variables.
class Person
var name as String
var age as int
var ID as String
var group as String
cue init(name as String, age as int, ID as String, group as String)
.name, .age, .ID, .group = name, age, ID, group
.callSomeMethod
With this:
class Person
var name as String
var age as int
var ID as String
var group as String
cue init(.name, .age, .ID, .group) # A dot means assign the argument to the object variable of that name
.callSomeMethod
Less typing . There are many cases where the only reason you even need to write an init is to assign values to object variables.