Tips for golfing in Swift
Ranges

One thing that is really helpful is creating ranges using the ... or ..&lt; operators

For example

array[0..&lt;n] //first n elements of array
array[k..&lt;n] //kth through nth elements of array
array[k...n] //kth through n-1 elements of array


So, to get the 2nd through 4th values of an array

let myArray = ["ab", "cd", "ef", "gh", "ij", "kl", "mn", "op"]
print(myArray[1..&lt;4]) //["cd", "ef", "gh"]


Practical Use

let a = [3, 1, 4, 1, 5, 9]


Using

for v in a[0...3]{print(v)}


Is 8 bytes shorter than

for n in 0...3{let v=a[n];print(v)}