Programming in Swift: Fundamentals · Challenge: Arrays |

This is a companion discussion topic for the original entry at

Unfortunately there are no instructions in the “Begin” playground of the challenge to say what it is the challenge is about or what we are supposed to do. Only the pastries array is there.
Great explanation on arrays though!

My mistake. I had grabbed the lecture download instead of the challenge download by mistake. I have the needed Challenges!

Is there any real difference between using the += to add to an array or using append like this:
players.append(contentsOf: [“Gloria”, “Hermione”])
Is one way better than the other?

@slogbelly I assume the only noticeable difference would be at the compiler-level. Otherwise, adding an array to another array with the += operator is the most elegant solution.


What is the difference between let teamOne = Array(players[4...7]) and let teamOne = players[4...7]?

They produce the same output in console as well as in the live preview sidebar, so just seeing why you went with a instead of b in this case.

Hey @bledden - there’s a subtle difference in those two forms.

If you execute the following code in a playground:

var players = [1,2,3,4,5]
let one = Array(players[2...4])
let two = players[2...4]
print(type(of: one))
print(type(of: two))

You’ll see that one is of type Array…while two is of type ArraySlice. So they contain the same data…but they’re not the same type of object, which may matter if you’re using more advanced operations on your arrays. Here’s some more information on ArraySlice: Apple Developer Documentation