View SystemLog.swift
// Note: This must be used in an Xcode project that contains a bridging header | |
// that includes <asl.h> | |
import Foundation | |
/// Provides high-level methods to access the raw data in | |
/// an ASL message. | |
struct SystemLogEntry { | |
/// Key-value pairs read from ASL message | |
let data: [String : String] |
View script.swift
#!/usr/bin/env xcrun swift | |
// $ chmod +x script.swift | |
// $ ./script.swift | |
// or $ ./script.swift -xcode=/Applications/Xcode-beta.app | |
import Foundation | |
@noreturn private func failWithError(message: String) { | |
print("🚫 \(message)") |
View optional-assignment.swift
infix operator ?= { | |
associativity right | |
precedence 90 | |
assignment | |
} | |
func ?=<T>(inout variable: T?, expr: @autoclosure () -> T) { | |
if variable == nil { | |
variable = expr() | |
} |
View matrix.swift
public struct MatrixIndex: BidirectionalIndexType { | |
public let x, y : Int | |
private let columns: Int | |
public func successor() -> MatrixIndex { | |
return (x + 1 == columns) ? | |
MatrixIndex(x: 0, y: y + 1, columns: columns) : | |
MatrixIndex(x: x + 1, y: y, columns: columns) |
View PrettyAnyAll.Swift
public extension IteratorProtocol { | |
mutating public func any(_ predicate: (Element) throws -> Bool) rethrows -> Bool { | |
guard let current = next() else { return false } | |
return try predicate(current) || any(predicate) | |
} | |
mutating public func all(_ predicate: (Element) throws -> Bool) rethrows -> Bool { | |
guard let current = next() else { return true } | |
return try predicate(current) && all(predicate) |