The most fundamental concepts in Swift that should be presented up front:
- variables and constants
- type safety
- type inference
Helpful:
println
assert
var name: String = "Jay"
name = "Capt. Jay"
println(name)
// Capt. Jay
var ints: [Int] = [1,2]
ints.append(3)
println(ints)
// [1, 2, 3]
let pi: Double = 3.14159
pi++
// ERRORZ
let ints: [Int] = [1,2]
ints.append(3)
// ERRORZ
var name: String = "Jay"
name = 42
// ERRORZ
var ints: [Int] = [1,2]
ints.append("Jay")
// ERRORZ
let pi = 3.14159
assert(pi is Double)
https://gist.github.com/iamvery/e7dcad7b3e0fc071cb58#file-1-short-circuit-spec-rb
- strings
- optionals
https://gist.github.com/iamvery/e7dcad7b3e0fc071cb58#file-1-short-circuit-swift
https://gist.github.com/iamvery/e7dcad7b3e0fc071cb58#file-2-kwargs-rb
- functions
- external parameters
https://gist.github.com/iamvery/e7dcad7b3e0fc071cb58#file-2-kwargs-swift
Warning: External parameters have different semantics as "methods"
https://gist.github.com/iamvery/e7dcad7b3e0fc071cb58#file-3-sym-to-proc-rb
- arrays
- function types
- closures
https://gist.github.com/iamvery/e7dcad7b3e0fc071cb58#file-3-sym-to-proc-swift
https://gist.github.com/iamvery/e7dcad7b3e0fc071cb58#file-4-truthy-rb
- conditionals
- Bool
- extensions
- protocols
https://gist.github.com/iamvery/e7dcad7b3e0fc071cb58#file-4-truthy-swift
https://gist.github.com/iamvery/e7dcad7b3e0fc071cb58#file-5-tap-rb
- generics
- inout
- explicit reference
https://gist.github.com/iamvery/e7dcad7b3e0fc071cb58#file-5-tap-swift
https://gist.github.com/iamvery/e7dcad7b3e0fc071cb58#file-6-fetch-rb
- Dictionary
- forced-internal parameter
- closures
fatalError
https://gist.github.com/iamvery/e7dcad7b3e0fc071cb58#file-6-fetch-swift
Note: It does not pass the missing key to the closure like Ruby!
https://gist.github.com/iamvery/e7dcad7b3e0fc071cb58#file-7-memoization-rb
- operators
- implicitly unwrapped optionals
https://gist.github.com/iamvery/e7dcad7b3e0fc071cb58#file-7-memoization-swift
https://gist.github.com/iamvery/e7dcad7b3e0fc071cb58#file-8-shovel-rb
- generic typealias
https://gist.github.com/iamvery/e7dcad7b3e0fc071cb58#file-8-shovel-swift
https://gist.github.com/iamvery/e7dcad7b3e0fc071cb58#file-9-regex-rb
- objc brigde (?)
- enum (sort of)
https://gist.github.com/iamvery/e7dcad7b3e0fc071cb58#file-9-regex-swift
Note: There is no formal type for regular expressions in Swift. You could do something like this to add some syntactic sugar: https://gist.github.com/iamvery/e7dcad7b3e0fc071cb58#file-9-regex-sugar-swift
https://gist.github.com/iamvery/e7dcad7b3e0fc071cb58#file-10-enumerable-rb
- functions
- generics
- types types types
- closures
- MOAR?
- http://austinzheng.com/2015/01/24/swift-seq/
Run any Ruby example with:
$ ruby 1-short-circuit.rb
Swift any Swift example with:
$ ./1-short-circuit.swift
Some of the scripts may not produce any output when successful, but failure would produce output. Certain examples are designed to "fail" for illustration.
Overall, I think this concept is interesting. I think the challenge is the breadth of what you cover, everything you cover is very technical (i.e. Need to first grasp Ruby fairly/very well to understand the Swift), and the amount of what you cover.