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 Observable: class { | |
associatedtype ObservableAction | |
typealias SubscriptionBlock = (ObservableAction) -> Void | |
var subscriptions: NSMapTable<AnyObject, AnyObject> { get set } | |
func notifyObservers(_ action: ObservableAction) -> Void |
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 ObserverStorage { | |
static let shared = ObserverStorage() | |
private var observablesMap: NSMapTable<AnyObject, AnyObject> = NSMapTable.weakToStrongObjects() | |
private func subscriptionsMap<T: Observable>(forObservable observable: T) -> NSMapTable<AnyObject, AnyObject> { | |
var subscriptionsMap = self.observablesMap.object(forKey: observable) as? NSMapTable<AnyObject, AnyObject> |
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
// | |
// Observable.swift | |
// Geotification | |
// | |
// Created by Roman Temchenko on 2016-10-29. | |
// Copyright © 2016 Temkos. All rights reserved. | |
// | |
import Foundation |
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 AssociationsStorage { | |
class Associations { | |
private var storage: [AnyHashable: Any] = [:] | |
func setValue(_ value: Any, forKey key: AnyHashable) { |
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 PlaygroundSupport | |
PlaygroundPage.current.needsIndefiniteExecution = true | |
func async<T>(_ executable: @escaping @autoclosure () -> T, _ priority: DispatchQoS.QoSClass = DispatchQoS.QoSClass.default, completion: @escaping (T) -> Void) { | |
DispatchQueue.global(qos: priority).async { | |
let result = executable() | |
DispatchQueue.main.async { |
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 CancellableDecorator { | |
private class Token { | |
var isValid = true | |
} | |
private var token: Token? |
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 Logger { | |
static var defaultLogger = Logger() | |
func log(_ 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
import UIKit | |
class TableViewContainerCell<Content: UIView>: UITableViewCell { | |
var content: Content | |
override init(style: UITableViewCellStyle, reuseIdentifier: String?) { | |
if let viewFromNib = Content.loadDefaultNib() { | |
content = viewFromNib | |
} |
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 performWithErrorPointer<T>(_ executable: @autoclosure @escaping () throws -> T, _ errorPointer: NSErrorPointer) -> T? { | |
do { | |
return try executable() | |
} | |
catch let error { | |
errorPointer?.pointee = error as NSError | |
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 | |
import UIKit | |
class RTTableViewControllerSectionModel: NSObject { | |
let cellModels: [RTTableViewControllerCellModel] | |
let tableView: UITableView | |
required init(_ tableView: UITableView, _ cellModels: [RTTableViewControllerCellModel]) { | |
self.tableView = tableView |
OlderNewer