Slice that Collection: A Swift guide

What are slices, and how are they used?

Prerequisites:

Terminology

Collections

The Array Summary

let ages = [1,5,12,15,2,26,67,36]
let sliceOfAges = ages[1...2]
sliceOfAges[0] // EXC_BAD_INSTRUCTION out of bounds

The Set Summary

let agesSet = [1,5,12,15,2,26,67,36]
let sliceOfAgesSet = agesSet.dropLast()

The Dictionary Summary

let agesDict : [Int: Int] = [0:1, 1:5, 2:12, 3:15, 4:2, 5:26, 6:67, 7:26]
let sliceOfDict = agesDict.dropLast()

Conclusion:

Extend your knowledge

The Twitter contact:

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store