in return number * 3 } let multiplier3 = {(number : Int) in return number * 3 } let multiplier3 = {(number : Int) in number * 3 } let multiplier3 = {number in number * 3 } let multiplier3 = { $0 * 3 }
{ while !pred() { block() } } And you would call it like this: var x = 0 until(x > 10) { x+=1 } 1 Example taken from http://airspeedvelocity.net/tag/auto_closure/
var name : String = "" } var juanito = Person() person.name = "Juanito" let juakin = Person() person.name = "Juakin" The juakin variable is immutable, but its property is not.
and controlled by a single owner. They can, but shouldn't create side effects. Classes are passed by reference, they can have multiple owners, they produce side effects (I/O, networking), they create state, they behave.
And then: let result : Result = .Success(Person()) switch result { case .Success(let person): doSomethingWithPerson(person) case .Error(let errorString): doSomethingWithError(errorString) }
types that can work with any type, subject to requirements that you define. You can write code that avoids duplication and expresses its intent in a clear, abstracted manner. --The Swift Programming Language
{ if let y = x { return f(y) } else { return nil } } T and U are placeholder types. It doesn't really matter what types they might be. The actual T and U will be determined when the map function is called.
respect the following: ▸ Pass a T that has the same type as the type that the function f receives. ▸ Return a U that has the same returning type as the function f.