Hi!
I'm new to Swift development and during reading an Intro to App Development with Swift I stuck with strange advice from the book (Lesson 20.2):
for choice in topChoices {
topCaptionSegmentedControl.insertSegment(withTitle: choice.emoji, at: topChoices.count, animated: false)
}
The "at" parameter implies it's an index/number of a segment, so it should be a counter (each element should have own position). So the code should be like this:
var i = 0
for choice in topChoices {
topCaptionSegmentedControl.insertSegment(withTitle: choice.emoji, at: i, animated: false)
i += 1
}
But the author of the book uses topChoices.count which is a constant value. In my case it's always equal to 3. So all three iterations of the loop we are inserting segments into the same position (3).
Can anybody explain how it works? I couldn't find a detailed explanation in the specs.