Printing off the content of Array or Set using for loop

642 views Asked by At

When trying to print off the content of Set or Array using for loop I don't receive values but number of them. For example:

var favouriteSports: Set = ["Snowboarding", "Skateboarding", "Surfing"]
for genre in favouriteSports {
    print("\(genre)")
}

What I wanted to receive in console is "Snowboarding, Skateboarding, Surfing" but instead I receive "(3 times)"

I'm running the above code in "playground". I just started with Swift, and I can't understand why such a simple thing is causing a problem.

1

There are 1 answers

0
Özgür Ersil On BEST ANSWER

It is a playground short styled screen. In your real project you will get the exact values. No problem. Also in a playground you can see the real values by clicking the "Show Result" button and then clicking the "All Values" button in the newly produced pane.

I've added a sample screen

enter image description here