You’ve probably seen these before. If not, well, buckle up. You’re in for a treat.
for i in [1, 2, 3] { print(i) }
Want to inefficiently calculate some numbers in the fibonacci sequence? Copy the code you see here.
func fib(n) { if n <= 1 { return n } return fib(n - 2) + fib(n - 1) } var i = 0 // Calculate some numbers while i < 15 { print(fib(i)) i = i + 1 }
TalkTalk supports protocols, which are like Swift protocols but they do less. But you don’t need to annotate as many types.
Also we’ve got string interpolation.
protocol Greetable { func greet(name: String) -> String } struct Person: Greetable { func greet(name) { "Hello, \(name)!" } } func greet(greetable: Greetable) { print(greetable.greet("pat")) } greet(Person())