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
protocol Dispatcher { | |
func dispatch(action: Action) | |
} | |
extension Dispatcher { | |
func bind(action: Action) -> Command { | |
return Command { self.dispatch(action: action) } | |
} | |
} |
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 UIKit | |
class CustomActivity: UIActivity { | |
override class var activityCategory: UIActivityCategory { | |
return .action | |
} | |
override var activityType: UIActivityType? { | |
guard let bundleId = Bundle.main.bundleIdentifier else {return nil} |
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 | |
class DisposeToken { | |
let block: (Void) -> Void | |
init(block: @escaping (Void) -> Void) { self.block = block } | |
deinit { block() } | |
} | |
class Store<State> { | |
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 func weakify<Value: AnyObject, Arguments, Result>( | |
_ function: @escaping (Value) -> (Arguments) -> Result, | |
object: Value, | |
default value: Result) | |
-> (Arguments) -> Result { | |
return { [weak object] arguments in | |
object.map { function($0)(arguments) } ?? 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
import Foundation | |
/// Protocol for NSLocking objects that also provide tryLock() | |
public protocol TryLockable: NSLocking { | |
func `try`() -> Bool | |
} | |
// These Cocoa classes have tryLock() | |
extension NSLock: TryLockable {} | |
extension NSRecursiveLock: TryLockable {} |
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 UIKit | |
class AnyViewClass: UIView {} | |
extension AnyView: NibInstantiable { } | |
let view: AnyViewClass = .fromNib() | |
type(of: view) //will be AnyViewClass |
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 class Token { | |
public typealias DisposeAction = () -> Void | |
private let action: DisposeAction | |
private var isDisposed: Bool = false | |
public init(action: @escaping DisposeAction) { self.action = action } | |
private func innerDispose() { |
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
class AnyInteractor: DBAccessable { | |
/* | |
easy access to self.dbService | |
*/ | |
} |
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
enum BinarySearchTree<T: Comparable> { | |
case empty | |
case leaf(T) | |
indirect case node(BinarySearchTree, T, BinarySearchTree) | |
} | |
extension BinarySearchTree { | |
var count: Int { | |
switch self { |
NewerOlder