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
// The MIT License (MIT) | |
// | |
// Copyright (c) 2017 Alexander Grebenyuk (github.com/kean). | |
import Foundation | |
import Alamofire | |
import RxSwift | |
import RxCocoa | |
// This post is **archived**. For a modern version that uses Async/Await and Actors, see the new article |
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
// The MIT License (MIT) | |
// | |
// Copyright (c) 2017 Alexander Grebenyuk (github.com/kean). | |
import Foundation | |
/// Manages cancellation tokens and signals them when cancellation is requested. | |
/// | |
/// All `CancellationTokenSource` methods are thread safe. | |
public final class CancellationTokenSource { |
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
// The MIT License (MIT) | |
// | |
// Copyright (c) 2017 Alexander Grebenyuk (github.com/kean). | |
import Foundation | |
import RxSwift | |
import RxCocoa | |
extension ObservableType { |
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 typealias Stack = UIStackView | |
public extension Stack { | |
@nonobjc public convenience init(_ views: UIView..., with: (UIStackView) -> Void = { _ in }) { | |
self.init(arrangedSubviews: views) | |
with(self) | |
} | |
@nonobjc public convenience init(_ views: [UIView], axis: UILayoutConstraintAxis = .horizontal, spacing: CGFloat = 0, alignment: UIStackViewAlignment = .fill, distribution: UIStackViewDistribution = .fill) { | |
self.init(arrangedSubviews: views) |
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
// MARK: - CancellationTokenSource | |
/// Manages cancellation tokens and signals them when cancellation is requested. | |
/// | |
/// All `CancellationTokenSource` methods are thread safe. | |
final class CancellationTokenSource { | |
/// Returns `true` if cancellation has been requested. | |
var isCancelling: Bool { | |
_lock.lock(); defer { _lock.unlock() } | |
return _observers == 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
class AsyncAwaitTests: XCTestCase { | |
func testAsyncAwait() { | |
XCTAssertEqual(fakeAsyncAwait().wait().value, 3) | |
} | |
} | |
func fakeAsyncAwait() -> Future<Int, Error> { | |
return Future.async { | |
// Add delay to demonstrate that `await` for `Future<_, Never>` don't |
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
// Configuration settings file format documentation can be found at: | |
// https://help.apple.com/xcode/#/dev745c5c974 | |
SUPPORTED_PLATFORMS = iphoneos macosx appletvos watchos iphonesimulator appletvsimulator watchsimulator | |
SWIFT_VERSION = 4.2 | |
IPHONEOS_DEPLOYMENT_TARGET = 9.0 | |
MACOSX_DEPLOYMENT_TARGET = 10.11 |
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
// The MIT License (MIT) | |
// | |
// Copyright (c) 2016-2019 Alexander Grebenyuk (github.com/kean). | |
import Foundation | |
/// Future extenions. | |
public struct FutureExtension<Base> { | |
/// Base object to extend. | |
public let base: Base |
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
// The MIT License (MIT) | |
// | |
// Copyright (c) 2020 Alexander Grebenyuk (github.com/kean). | |
import CoreData | |
final class FetchedEntities<Element: NSManagedObject>: NSObject, NSFetchedResultsControllerDelegate, RandomAccessCollection, ObservableObject { | |
private let controller: NSFetchedResultsController<Element> | |
init(context: NSManagedObjectContext, request: NSFetchRequest<Element>) { |
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
// A speculative _ViewRendererHost implementation which uses Mirror (Swift reflection) to find all | |
// of the dynamic properties (`DynamicProperty`) associated with a given view (`View`), observe | |
// the changes to these properties and automatically refresh the view whenever any of these property change. | |
protocol _DynamicProperty { | |
var objectWillChange: AnyPublisher<Void, Never> { get } | |
} | |
extension ObservedObject: _DynamicProperty { | |
var objectWillChange: AnyPublisher<Void, Never> { |