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 | |
/// Weakly captures an object | |
/// | |
/// Actually the same as `weak` but initializable | |
/// | |
/// Usage: | |
/// ``` | |
/// Weak(object) | |
/// Weak(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
import Foundation | |
import LocalAuthentication | |
@propertyWrapper | |
public class Authenticated { | |
public typealias Action = () -> Void | |
private var _action: Action = {} | |
private var _onStart: Action? | |
private var _onSuccess: 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
/* | |
ModelBinding<T>: a simple class for binding a Flutter app to a immutable | |
model of type T. | |
This is a complete application. The app shows the state of an instance of | |
MyModel in a button's label, and replaces its MyModel instance when the | |
button is pressed. | |
ModelBinding is an inherited widget that must be created in a context above |
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
// UICollectionView Objective-C example | |
- (void)viewWillAppear:(BOOL)animated { | |
[super viewWillAppear:animated]; | |
NSIndexPath *selectedIndexPath = [[self.collectionView indexPathsForSelectedItems] firstObject]; | |
if (selectedIndexPath != nil) { | |
id<UIViewControllerTransitionCoordinator> coordinator = self.transitionCoordinator; | |
if (coordinator != nil) { | |
[coordinator animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext> context) { |
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
// https://github.com/avito-tech | |
private class ObserverBox<T>: Hashable { | |
typealias Observer = T | |
private(set) weak var disposable: AnyObject? | |
private let objectIdentifier: ObjectIdentifier | |
var observers = [Observer]() | |
let hashValue: Int | |
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
// https://github.com/avito-tech | |
// | |
// Sampler is like a baby of Debouncer and Throttler. | |
// | |
// Unlike Debouncer, sampler executes action immediately (if there are no actions before, for time > delay) | |
// Unlike Throttler it guarantees that last action in sequence will be executed (see last error in example) | |
/// CAUTION: This class isn't thread-safe | |
public final class Sampler { | |
// MARK: - Public properite |
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
let a: Double? = 1.0 | |
let b: Double? = 2.0 | |
let c: Double? = 3.0 | |
let d: Double? = 4.0 | |
let e: Double? = 5.0 | |
let f: Double? = 6.0 | |
let g: Double? = 7.0 | |
extension Optional { | |
func `or`(_ value : Wrapped?) -> Optional { |
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
// Either put this in a separate file that you only include in your macOS target | |
// or wrap the code in #if os(macOS) / #endif | |
import Cocoa | |
// Step 1: Typealias UIImage to NSImage | |
typealias UIImage = NSImage | |
// Step 2: You might want to add these APIs that UIImage has but NSImage doesn't. | |
extension NSImage { |
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 with<T>(_ item: inout T, action: (inout T) -> Void) { | |
action(&item) | |
} | |
public func with<T>(_ item: T, action: (T) -> Void) { | |
action(item) | |
} | |
public func with<T: AnyObject>(_ item: T, action: (T) -> Void) { | |
action(item) |
NewerOlder