[swift-users] Named parameters

David Keck davidskeck at fastmail.com
Sat Jan 23 14:02:03 CST 2016


Beginner here, so this may be obvious to some people, but I can't figure out why the first argument in a function call isn't referenced by name, but all subsequent ones are. I think I have the syntax down, but I just don't get why it is that way.

For example:
func add(notRequired: Int, required: Int) -> Int {
	return notRequired + required
}

let result = add(2, required: 5)
// Not allowed:
// let result = add(notRequired: 2, required: 5)

I just want to know the rationale behind this.


More information about the swift-users mailing list