I really enjoyed reading your article. Here are a few minor changes based on newer versions of Swift.
Ranges
The half-open range operator .. is now ..<.
Empty Collections
Typed arrays are no longer declared and created using String[](); use [String]() instead.
Sort
Your Sort syntax is invalid:
sort([1, 5, 3, 12, 2]) { $0 > $1 }
sort takes an array as inout parameter, which you aren't passing here
you are passing in an immutable array, but the array needs to be mutable
you can just pass the comparison operator.
So this would work:
var numbers = [1, 5, 3, 12, 2]
sort(&numbers)
Or this:
var numbers = [1, 5, 3, 12, 2]
numbers.sort(<)
Or you can return the sorted numbers using sorted instead of sort:
let immutableNumbers = [1, 5, 3, 12, 2]
let immutableSortedNumbers = [1, 5, 3, 12, 2].sorted(<)
Downcasting
This is more of a suggestion than a correction. You might want to cover optional downcasting (let movie = object as? Movie); I don't know if there's a Scala equivalent (I don't know Scala).
I really enjoyed reading your article. Here are a few minor changes based on newer versions of Swift.
Ranges
The half-open range operator
..
is now..<
.Empty Collections
Typed arrays are no longer declared and created using
String[]()
; use[String]()
instead.Sort
Your Sort syntax is invalid:
sort
takes an array as inout parameter, which you aren't passing hereSo this would work:
Or this:
Or you can return the sorted numbers using
sorted
instead ofsort
:Downcasting
This is more of a suggestion than a correction. You might want to cover optional downcasting (
let movie = object as? Movie
); I don't know if there's a Scala equivalent (I don't know Scala).