I recently started learning Swift and came across a Swift switches, it seems that switches must be exhaustive in Swift, for example.
This will cause a compiler error
let nums = 1...5
for num in nums
{
switch num
{
case 2:
// Do Something
// Will throw a comilation error unless default: was added
}
}
Whilst in C#, this is perfectly acceptable
var nums = new[] {1, 2, 3, 4, 5};
foreach (var num in nums)
{
switch (num)
{
case 2:
// Do Something
break;
}
}
Is this just a infrastructure preference or is there some other reason for this?