jakarmy/swift-summary

[03 - Collection Types] subscript syntax

aurelien-ldp opened this issue · 2 comments

By default the following fails (on my version, at least):

shoppingList[4...6] = ["Bananas", "Apples"]

As explained in the documentation:

You can’t use subscript syntax to append a new item to the end of an array.

https://developer.apple.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/CollectionTypes.html

This should fix the problem:

shoppingList[3...4] = ["Bananas", "Apples"]

This replaces elements with indices 2, 3, 4 with ["Bananas", "Apples"] therefore it removes one extra element:

shoppingList[2...4] = ["Bananas", "Apples"]

This is the correct way to replace elements with indices 3 and 4:

shoppingList[3...4] = ["Bananas", "Apples"]

Also, this problem is solved in #6

My bad, of course you're right ! I've edited my post.