Let’s say I have a class Foo
:
class Foo {
let bar: String
let baz: String
}
Do I really have to write the memberwise initializer by hand?
init(bar: String, baz: String) {
self.bar = bar
self.baz = baz
}
It’s pure boilerplate.
If you can work with value semantics instead of reference semantics, you can use a Struct instead of a Class, they have automatic memberwise initializers.
If not, then you have to provide the full init yourself for your class.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With