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 | |
private let log = Log(topic: .rateLimit) | |
/// Timeout based rate limit helper class. | |
final class RateLimit { | |
// MARK: - Private | |
private let timeout: TimeInterval |
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 UIView { | |
static var debugColors: [UIColor] { | |
return [ | |
.red, | |
.green, | |
.blue, | |
.cyan, | |
.yellow, | |
.magenta, |
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
/// 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
extension XCTestCase { | |
struct AwaitError: Error {} | |
/** | |
This function is useful for asynchronous testing and acts as a wrapper around test expectations. | |
Consider the following example: | |
```swift | |
// Let's asume we have an async function with the following signature: |
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
extension Equatable { | |
func oneOf(other: Self...) -> Bool { | |
return other.contains(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
extension XCTestCase { | |
enum FixtureError: Error { | |
case resourceNotFound | |
case invalidFormat | |
} | |
/// Loads the json fixture with the given name from disk and returns a json object. | |
/// - Parameter fileName: The anme of the fixture on disk (without the type suffix). | |
/// - Throws: Any errors encountered during the process. |
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) { |
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 | |
} | |
NewerOlder