Why variadic parameters cannot be marked as inout in swift?

215 views Asked by At

Apple documentation says,

"In-out parameters cannot have default values and variadic parameters cannot be marked as inout".

Why we are restricted from doing so?

2

There are 2 answers

0
Akash Sharma On

As of my understanding till now:

We can not pass Constant/Literals to input parameters. Because Constant/Literals are immutable and can not be changed.

But for Variadics, we can pass Constant/Literals as parameters. So if we can make the Variadics as inout, then it contradicts the above facts.

Regarding default values for Variadic parameter, the default value of Variadic parameter is an empty array. Playground image attached.

Playground Image

Let me know in case I have an incorrect understanding.

0
Raj Anand On

We can not pass Constant/Literals to input parameters. Because Constant/Literals are immutable and can not be changed.

But for Variadics, we can pass Constant/Literals as parameters. So if we can make the Variadics as inout, then it contradicts the above facts.