I came across such statements as the following in Matt Neuburg's iOS 13 Programming Fundamentals with Swift:
When you cycle through a sequence with for...in, what you’re actually cycling through is a copy of the sequence. That means it’s safe to mutate the sequence while you’re cycling through it:
And the author supplied the following example for the above statements:
var s : Set = [1,2,3,4,5]
for i in s {
if i.isMultiple(of:2) {
s.remove(i)
}
} // s is now [1,3,5]
In the example above, we can see that the original array was altered from [1,2,3,4,5,6] to [1,3,5]. That means the array itself was changed. So, the for in loop wasn't looping through a copy of the original array but the array itself. That seems to contradict the author's statements above.
So, I'm not sure whether the author's statements are true or not. Would anyone please clarify this matter? Thank you very much.
Objective Cfor example.s.remove(i)remove the element from the sets...