Changes implementation of two overloads of `Disposables.create()` to avoid deprecation warnings.

This commit is contained in:
Mo Ramezanpoor 2016-08-10 14:33:39 +01:00
parent 341ef8fc3b
commit 6d17e711ab
2 changed files with 18 additions and 6 deletions

View File

@ -36,7 +36,13 @@ public final class AnonymousDisposable : DisposeBase, Cancelable {
_disposeAction = disposeAction
super.init()
}
// Non-deprecated version of the constructor, used by `Disposables.create(with:)`
private init(disposeAction: DisposeAction) {
_disposeAction = disposeAction
super.init()
}
/**
Calls the disposal action if and only if the current instance hasn't been disposed yet.
@ -53,3 +59,11 @@ public final class AnonymousDisposable : DisposeBase, Cancelable {
}
}
}
public extension Disposables {
static func create(with action: () -> ()) -> Disposable {
return AnonymousDisposable(disposeAction: action)
}
}

View File

@ -14,12 +14,10 @@ public struct Disposables {
public extension Disposables {
static func create() -> Disposable {
return NopDisposable.instance
}
private static let noOp: Disposable = NopDisposable()
static func create(with action: () -> ()) -> Disposable {
return AnonymousDisposable(action)
static func create() -> Disposable {
return noOp
}
static func create(_ disposable1: Disposable, _ disposable2: Disposable, _ disposable3: Disposable) -> Disposable {