This initialiser will cause an error complaining that "with" is implied for the first parameter of an initialiser; did you mean name?
init(withName: String){
}
I'm not sure what this means, if it provides automagically the withName
external parameter name if I call it name or what...
If I change it to
init(name: String){
}
any attempt at calling it init(with: "joe")
or init(withName: "Joe")
will fail. So I have no idea what the error message is telling me and how I can declare it so I call it init(withName: "joe")
.
In Swift you should not add with
to the initializer. The initializer should be init(name:)
and you should call it as Object(name: "joe")
.
This is because of how Swift methods bridge to ObjC. In ObjC, that initializer will automatically be translated to initWithName:
. If you named it init(withName:)
it would become initWithWithName:
.
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