This file contains hidden or 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
| var a = 2 | |
| enum Status { | |
| case Okay | |
| case NotOkay | |
| } | |
| func doSomeWork() -> Status { | |
| a += 2 | |
This file contains hidden or 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
| class Lazy<T> { | |
| let expression: () -> T | |
| lazy var value: T = self.expression() | |
| init(_ expression: () -> T) { | |
| self.expression = expression | |
| } | |
| } | |
| let range = 0..<1000000000 |
This file contains hidden or 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 Error : ErrorType { | |
| case randomError | |
| } | |
| func testFunction(@autoclosure closure: () throws -> Void) { | |
| do { | |
| print(try closure()) | |
| } catch let err { print(err) } | |
| } |
This file contains hidden or 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
| class MyClass { | |
| def someFunction = { | |
| println(MyClass.word) | |
| } | |
| } | |
| object MyClass { | |
| val word = "test" | |
| } |
This file contains hidden or 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 | |
| var running = false | |
| print("press enter to countdown") | |
| readLine() | |
| repeat { | |
| for i in 1...3 { | |
| print(i) | |
| NSThread.sleepForTimeInterval(1) |
This file contains hidden or 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 | |
| func takeSocketEmittable(item: SocketData) { | |
| switch item { | |
| case let .array(array): | |
| print("array: \(array)") | |
| case let .bool(bool): | |
| print("bool: \(bool)") | |
| case let .data(data): | |
| print("data: \(data)") |
This file contains hidden or 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 String { | |
| var isBlank: Bool { | |
| if self.isEmpty { return true } | |
| for c in characters where String(c) != " " { | |
| return false | |
| } | |
| return true | |
| } |
This file contains hidden or 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
| class Thing { | |
| var n = 100 | |
| func add(n: Int) { | |
| self.n += n | |
| } | |
| } | |
| let a = Thing() | |
| let addBoundToA = Thing.add(a) |
This file contains hidden or 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
| // | |
| // main.swift | |
| // youtube | |
| // | |
| // Created by Erik Little on 7/30/16. | |
| // Copyright © 2016 Erik Little. All rights reserved. | |
| // | |
| import Foundation |
This file contains hidden or 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/swift | |
| // Program that lets your media keys control [cmus](https://github.com/cmus/cmus) | |
| // You'll need to run `launchctl unload -w /System/Library/LaunchAgents/com.apple.rcd.plist` or the media keys | |
| // will still try control iTunes | |
| import AppKit | |
| final class MediaKeys : NSApplication { | |
| var repeated = false |