0

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?

rmaddy
  • 314,917
  • 42
  • 532
  • 579
rishu1992
  • 1,414
  • 3
  • 14
  • 33
  • I cannot even imagine a use case for such a thing. – Sulthan Dec 15 '18 at 14:14
  • func trim(comparables: inout C..., min: C, max: C) { for comparable in comparables { if comparable < min { comparable = min } if comparable > max { comparable = max } } } – Valentin Oct 27 '19 at 12:42

2 Answers2

0

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.

Akash Sharma
  • 756
  • 7
  • 10
-1

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.

Raj Anand
  • 1
  • 1