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
Use at your own risk! Swift moves quickly so it is possible | |
info in these scripts is out of date. | |
To use build-redist-package.sh you'll need a Mac Developer ID certificate. | |
The build will take a long time but the custom my-presets.ini | |
file skips tests to speed things up a fair amount. | |
rebuild-toolchain.sh builds your own Personal local toolchain | |
over top of the previous one, so if you symlink it into the | |
actual Toolchains directory you can always have the most |
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
// Paste me into a playground! | |
import Cocoa | |
//: # Basic Setup | |
protocol FancyProtocol { | |
associatedtype Thing | |
func holdPinkyUp(x: Thing) | |
} |
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 | |
public enum TruncateMode: Int { | |
case Head = 0 | |
case Middle = 1 | |
case Tail = 2 | |
} | |
public extension String { | |
func nilIfEmpty() -> 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
// If you want types initializable from String literals | |
// but don't want to implement three separate initializers. | |
extension ExpressibleByUnicodeScalarLiteral where Self: ExpressibleByStringLiteral, Self.StringLiteralType == String { | |
public init(unicodeScalarLiteral value: String) { | |
self.init(stringLiteral: value) | |
} | |
} |
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
/// Appends a value to an array within a dictionary without triggering a copy. | |
/// Necessary in Swift 3 but expected to be obsoleted as the way inout works | |
/// will be changed (eliminating the need for the write-back copy) | |
func append<K, V>(value: V, toKey key: K, in dict: inout [K : Array<V>]) { | |
var a: [V]? = [] | |
swap(&a, &dict[key]) | |
a = a ?? [] | |
a!.append(value) | |
swap(&a, &dict[key]) |
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 < <T: Comparable>(lhs: T?, rhs: T?) -> Bool { | |
switch (lhs, rhs) { | |
case let (l?, r?): | |
return l < r | |
case (nil, _?): | |
return true | |
default: | |
return false | |
} | |
} |
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
// Russ Bishop | |
// PlanGrid | |
// MIT licensed, use freely. | |
public protocol OptionalType { | |
associatedtype WrappedType | |
init() | |
} | |
extension Optional: OptionalType { |
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
// MIT license, no warranty. | |
// Now updated for Swift 3.0 | |
// Warning: This is just example code. In production you would want | |
// unit tests and ASAN tests. | |
/** | |
A thin wrapper over an unsafe buffer. | |
- warning: For the rare case where performance profiling has proven native Swift `Array` to be a problem. |
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 NSFileHandle: OutputStreamType { | |
public func write(string: String) { | |
if let data = string.dataUsingEncoding(NSUTF8StringEncoding, allowLossyConversion: true) { | |
self.writeData(data) | |
} | |
} | |
} |
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
// Written by Russ Bishop | |
// MIT licensed, use freely. | |
// No warranty, not suitable for any purpose. Use at your own risk! | |
struct PointEncoder { | |
// When parsing if we get a wildly large value we can | |
// assume denial of service or corrupt data. | |
static let MaxPoints = 1_310_719 | |
// How big an Int64 is |
NewerOlder