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
dispatchPrecondition( | |
condition: DispatchPredicate.onQueue(DispatchQueue.main) | |
) |
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
/// Type erased Optional protocol | |
protocol OptionalType { | |
associatedtype WrapType | |
var isSome: Bool { get } | |
var isNone: Bool { get } | |
var unsafelyUnwrapped: WrapType { get } | |
} |
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
/// A type representing an alternative of one of two types. | |
/// | |
/// By convention, and where applicable, `Left` is used to indicate failure, while `Right` is used to indicate success. (Mnemonic: “right” is a synonym for “correct.”) | |
/// | |
/// Otherwise, it is implied that `Left` and `Right` are effectively unordered alternatives of equal standing. | |
public enum Either<Left, Right> { | |
case left(Left) | |
case right(Right) | |
/// Returns the value of `Left` instances, or `nil` for `Right` instances. |
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 | |
import RxSwift | |
import RxCocoa | |
extension ObservableType { | |
/// Unwraps an Optional Element if it's present | |
/// | |
/// - Returns: The safely unwrapped item | |
func unwrap<T>() -> Observable<T> where E == Optional<T> { | |
return filter { $0 != nil }.map { $0! } |
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
final class HelloWorldViewModel: ViewModelType { | |
let input: Input | |
let output: Output | |
struct Input { | |
let name: Anyobserver<String> | |
} | |
struct Output { | |
let greeting: Driver<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
prefix operator ^ | |
prefix func ^<Root, Value>(keyPath: KeyPath<Root, Value>) -> (Root) -> Value { | |
return { $0[keyPath: keyPath] } | |
} |
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 PermutationIterator<T>: IteratorProtocol { | |
private var hasReturnedInitial = false | |
private var a: [T] | |
private var c: [Int] | |
private let n: Int | |
private var i = 0 | |
public init<C: Collection>(_ values: C) where C.Element == T { | |
a = Array(values) | |
n = a.count |
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
#!/bin/sh | |
# | |
# Lint any changed files using swiftlint. | |
# | |
# This works both independently and as a run phase script. | |
# Path to installed version of Swift lint. | |
readonly SWIFT_LINT_PATH=$(which swiftlint) | |
if [ -z "$SWIFT_LINT_PATH" ]; then |
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
-- Sets your audio input source to "Internal Microphone" | |
-- Frequently needed if you use bluetooth headpohones and | |
-- run the Xcode iOS simulator, which will often set your | |
-- headphones to be the input device, resulting in a drastic | |
-- decrease in sound quality, and making it mono | |
tell application "System Preferences" to activate | |
tell application "System Preferences" | |
reveal anchor "input" of pane id "com.apple.preference.sound" | |
end tell |
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 UIWindow { | |
final class StatusBarPreferringViewController: UIViewController { | |
// MARK: - Inputs | |
private let statusBarStyle: UIStatusBarStyle | |
// MARK: - Initialization | |
init(statusBarStyle: UIStatusBarStyle) | |
self.statusBarStyle = statusBarStyle |