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
import Foundation | |
class Logger { | |
enum Level: Int, Printable { | |
case Noise | |
case Normal | |
case Important | |
case Critical | |
var description: String { |
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
// Playground - noun: a place where people can play | |
import Cocoa | |
struct MagicNumber { | |
var skip: Bool = false | |
var f: Float? { | |
didSet { |
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
func foo(bar: Float) { | |
var x: Float | |
((bar, x): Int) { | |
//bar is now an Int, but only in this scope | |
} | |
} |
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
enum Settings: Int { | |
case Suffix | |
case SignificantDigits | |
case Count | |
func toString() -> String { | |
switch(self) { | |
case .Suffix: | |
return "Suffix" | |
case .SignificantDigits: |
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
enum Settings: Int { | |
case Suffix | |
case SignificantDigits | |
case Count | |
func toString() -> String { | |
switch(self) { | |
case .Suffix: | |
return "Suffix" | |
case .SignificantDigits: |
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
extension T[] { | |
func filterMap<U>(transform: (T) -> U?) -> U[] { | |
var newArray = U[] | |
for i in self { | |
if let filterMappedValue = transform?(i) { | |
newArray += filterMappedValue | |
} | |
} | |
return newArray | |
} |
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
% xcrun swift 1 ↵ | |
Welcome to Swift! Type :help for assistance. | |
1> class Foo { | |
2. var num = 1 | |
3. var string = "String" | |
4. } | |
5> | |
6> reflect(Foo())[0] | |
$R1: (String, Mirror) = { | |
0 = "num" |
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
func takeThree(i : Int, j : Int, k : Int) { | |
println("\(i)\(j)\(k)") | |
} | |
let arg = (1,2,3) | |
takeThree(arg) |
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
// Playground - noun: a place where people can play | |
import Cocoa | |
let a = [0..5, 0..5] | |
func conjugate(sets: Array<Range<Int>>) -> Array<(Int, Int)> { | |
var conjugates = Array<(Int, Int)>() | |
for setA: Range<Int> in sets { | |
for setB: Range<Int> in sets { |
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
struct LocalizedString: StringInterpolationConvertible, StringLiteralConvertible { | |
typealias StringLiteralType = String | |
typealias ExtendedGraphemeClusterLiteralType = String | |
var s:String | |
init(_ string: String) { | |
s = string | |
} | |
NewerOlder