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 | |
import PlaygroundSupport | |
PlaygroundPage.current.needsIndefiniteExecution = true | |
extension Comparable { | |
/// Clamp the value between `low` and `high` | |
func clamp(_ low: Self, _ high: Self) -> Self { |
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 Throttle { | |
let delay: TimeInterval | |
private var workItem: DispatchWorkItem? | |
private let queue: DispatchQueue | |
init(delay: TimeInterval, queue: DispatchQueue = .main) { | |
self.delay = delay | |
self.queue = queue | |
} |
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 DispatchQueue { | |
/// Helper method to use when reading from a resource | |
/// that is being isolated by this queue. | |
/// | |
/// Using this method retriving a value like this: | |
/// ``` | |
/// var result: T? | |
/// queue.sync { | |
/// result = resource["key"] |
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 Dictionary { | |
subscript<T: RawRepresentable>(_ key: T) -> Value? where T.RawValue == Key { | |
return self[key.rawValue] | |
} | |
} | |
// Usage: | |
enum Type: Int { | |
case easy | |
} |
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 MobileCoreServices | |
struct UTType: CustomStringConvertible { | |
let value: CFString | |
init?(mimeType: String) { | |
guard let UTI = UTTypeCreatePreferredIdentifierForTag(kUTTagClassMIMEType, mimeType as CFString, nil)?.takeUnretainedValue() else { return nil } | |
value = UTI | |
} | |
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 | |
extension Equatable { | |
/// Whether `self` is contained in a list of other values. | |
/// Variadic version, see the method below for the generic implementation. | |
/// | |
/// - Parameter others: The values that `self` should be checked against. | |
/// - Returns: Whether or not `self` is one of the provided other values. | |
func isOne(of others: Self...) -> Bool { |
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 SystemConfiguration | |
extension Notification.Name { | |
public static let reachabilityChanged = Notification.Name(rawValue: "reachabilityChanged") | |
} | |
protocol ReachabilityObserver: class { | |
func reachabilityDidChange(_ reachability: Reachability) | |
} |
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 | |
final class Log: NSObject { | |
enum Topic: String { | |
case network, app | |
} | |
private enum Level: String { | |
case info = "" |
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
/// Attention: Changes made to this file will not have any effect and will be reverted | |
/// when building the project. Please adjust the Stencil template `asset_extensions.stencil` instead. | |
/// See https://github.com/SwiftGen/SwiftGen#bundled-templates-vs-custom-ones for more information. | |
import UIKit | |
// MARK: - Private Helper - | |
private final class BundleToken {} | |
private let bundle = Bundle(for: BundleToken.self) |
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 OnceToken { | |
private(set) lazy var perform: () -> Void = { | |
self.closure() | |
return {} | |
}() | |
private let closure: () -> Void | |
init(execute closure: @escaping () -> Void) { |