This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let values = [4, 8, 15, 16, 23, 42] | |
let meanValue = values.reduce(0, +) / values.count | |
// + is a operator function and we can pass it in to reduce as the function parameter. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
operator infix <=> {} | |
infix func <=> <T>(inout left: T, inout right: T) { | |
let tmp = left | |
left = right | |
right = tmp | |
} | |
var a = 1337 | |
var b = 4711 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
operator postfix ** {} | |
postfix func ** (value: Int) -> Int { | |
return value * value | |
} | |
let a = 3** + 1 | |
// a now contains 10 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
operator infix <- {} | |
infix func <- <T>(inout left: T, right: T) { | |
left = right | |
} | |
var value = 0 // Initialize | |
value <- 1337 | |
// value now contains 1337 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/xcrun swift | |
println("Hello, World!") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* syscon - A tool for reading the system console from an iOS device | |
* via USB and displaying it in the OS X terminal in "real time". | |
* | |
* This tool and its source code is hereby released into the public domain. | |
* No warranty given, no responsibility taken. Use at your own risk. | |
* | |
* How to build: | |
* | |
* clang -o syscon -framework CoreFoundation -framework MobileDevice |
NewerOlder