Swift Pair Programming – Day 4

Today Nick and I worked on the insertion sort in swift. The biggest problem we ran into was learning how to iterate through an array in swift backward. We ended up using “stride” to define the start, end, and increment amount.

Here’s the code for stride:

for index in stride(from: 5, to: 1, by: -1) {

There is also a way to do this in swift using the reverse function:

// Print 10 through 1
for i in reverse(1...10) {

Next week we’ll be tackling the merge sort.

Author: David Neely

Professional Software Developer. Technology and Web Coordinator at the University of Hawaii's Manoa Career Center.