Post

Replies

Boosts

Views

Activity

array index confusion
Hello, I am curently study the Apple book "Develop in Swift EXPLORATION" and here is something I don't understand: at page 392, there is this advice, of how to populate a segmentedControl with some emoji, each emoji being previously saved in the elements of "topChoices" array. Here is how the book advice to proceed: for choice in topChoices { topCaptionSegmentedControl.insertSegment(withTitle: choice.emoji, at: topChoices.count,animated: false) } My confusion come from the fact that although the property "count" means the number of elements in that array, in this above case, it seems that topChoices . count means each index, from zero to the last element (because the segmentedControl is populated with each emoji saved in topChoices elements). If topChoices.count means the number of elements in the topChoices array, that implies the segmentedControl would have been populated ONLY with the emoji being saved in the last element of the topChoices array. But, the segmentsControl gets populated with all emojis from the topChoices array. How is that? Thank you!
2
0
656
Oct ’22