diff options
| author | Jon Petersson <jon.petersson@kvadrat.se> | 2023-09-04 23:53:38 +0200 |
|---|---|---|
| committer | Jon Petersson <jon.petersson@kvadrat.se> | 2023-09-07 16:46:26 +0200 |
| commit | 7509670dd5d5cf3082feeb508ea5b3aabf5430cc (patch) | |
| tree | f8f6cef66111e26a630740732840f361358f3376 /ios/Operations/OperationBlockObserverSupport.swift | |
| parent | 827a84c9287705e30487f2f53b360e05dc418f54 (diff) | |
| download | mullvadvpn-7509670dd5d5cf3082feeb508ea5b3aabf5430cc.tar.xz mullvadvpn-7509670dd5d5cf3082feeb508ea5b3aabf5430cc.zip | |
Fix or report all current smaller Swiftlint warnings in xcode
Diffstat (limited to 'ios/Operations/OperationBlockObserverSupport.swift')
| -rw-r--r-- | ios/Operations/OperationBlockObserverSupport.swift | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/ios/Operations/OperationBlockObserverSupport.swift b/ios/Operations/OperationBlockObserverSupport.swift new file mode 100644 index 0000000000..196adee763 --- /dev/null +++ b/ios/Operations/OperationBlockObserverSupport.swift @@ -0,0 +1,35 @@ +// +// OperationBlockObserverSupport.swift +// Operations +// +// Created by Jon Petersson on 2023-09-07. +// Copyright © 2023 Mullvad VPN AB. All rights reserved. +// + +import Foundation + +public protocol OperationBlockObserverSupport {} + +extension OperationBlockObserverSupport where Self: AsyncOperation { + /// Add observer responding to cancellation event. + public func onCancel(_ fn: @escaping (Self) -> Void) { + addBlockObserver(OperationBlockObserver(didCancel: fn)) + } + + /// Add observer responding to finish event. + public func onFinish(_ fn: @escaping (Self, Error?) -> Void) { + addBlockObserver(OperationBlockObserver(didFinish: fn)) + } + + /// Add observer responding to start event. + public func onStart(_ fn: @escaping (Self) -> Void) { + addBlockObserver(OperationBlockObserver(didStart: fn)) + } + + /// Add block-based observer. + public func addBlockObserver(_ observer: OperationBlockObserver<Self>) { + addObserver(observer) + } + + // swiftlint:disable:next file_length +} |
