I have simple class:
class WmAttendee{
var mEmail:String!
var mName:String!
var mType:Int!
var mStatus:String = "0"
var mRelationShip:String!
init( email:String, name:String, type:Int) {
self.mEmail = email
self.mName = name
self.mType = type
}
convenience init( email:String, name:String, type:Int, status:String, relationShip:String) {
self.init(email: email, name: name, type: type)
self.mStatus = status
self.mRelationShip = relationShip
}
}
When I try to test 2nd constructor with 5 parameters, I get: Extra argument 'status' in call
var att1 = WmAttendee(email: "myMail", name: "SomeName", type: 1); // OK
var att2 = WmAttendee(email: "mail2", name: "name2", type: 3, status: "2", relationShip: 3)
// ERROR Extra argument 'status' in call
Why? Do I miss something?
Thanks,
Based on your method signature:
convenience init( email:String, name:String, type:Int, status:String, relationShip:String)
relationshipStatus
should be a String
and not an Int
:
var att2 = WmAttendee(email: "mail2", name: "name2", type: 3, status: "2", relationShip: "3")
Since you're not passing the correct type for relationshipStatus
, the compiler can't match the method signature for your convenience init and falls back the the default init (the closest match it can find) which triggers the Extra argument
error.
Your are passing a parameter of the wrong type to your function. 'RelationShip' must be of type String, but you are passing an Integer. Yes, the compiler error is misleading, but then again swift is still in beta.
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