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
// 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] |
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/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)") |
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
infix operator ?= { | |
associativity right | |
precedence 90 | |
assignment | |
} | |
func ?=<T>(inout variable: T?, expr: @autoclosure () -> T) { | |
if variable == nil { | |
variable = expr() | |
} |
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
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) |
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
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) |