Skip to content

Instantly share code, notes, and snippets.

@mono0926
Last active November 11, 2019 08:43
Show Gist options
  • Select an option

  • Save mono0926/78bf126d9bd887276793410890c44e38 to your computer and use it in GitHub Desktop.

Select an option

Save mono0926/78bf126d9bd887276793410890c44e38 to your computer and use it in GitHub Desktop.
struct DisposableWrapper: Disposable {
private let disposable: Disposable
init(disposable: Disposable) {
self.disposable = disposable
}
func dispose() {
disposable.dispose()
}
}
public extension Observable {
public func `do`(onDisposed: @escaping () -> ()) -> Observable {
return Observable.using({
return DisposableWrapper(disposable: Disposables.create(with: onDisposed))
}, observableFactory: { _ -> Observable in
return self
})
}
}
@mono0926
Copy link
Copy Markdown
Author

DisposableWrapper でくるまないと、以下のコンパイルエラー(´・︵・`)

Cannot convert value of type '() -> Disposable' to expected argument type '() -> _'

@mono0926
Copy link
Copy Markdown
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment