diff options
| author | Andrej Mihajlov <and@mullvad.net> | 2022-09-25 16:34:23 +0200 |
|---|---|---|
| committer | Andrej Mihajlov <and@mullvad.net> | 2022-09-26 16:35:38 +0200 |
| commit | f389956c2cd884df142adbf00ff2ac7e2f69c2b2 (patch) | |
| tree | 5f7d4869324760eb4ba0107c0356edc89efd1457 /ios/Shared | |
| parent | 2e83b1ca27ff243a615ff10c94c20840b38dfd45 (diff) | |
| download | mullvadvpn-f389956c2cd884df142adbf00ff2ac7e2f69c2b2.tar.xz mullvadvpn-f389956c2cd884df142adbf00ff2ac7e2f69c2b2.zip | |
Move AsyncOperation into Operations static library and add separate tests
Diffstat (limited to 'ios/Shared')
| -rw-r--r-- | ios/Shared/Swizzle.swift | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/ios/Shared/Swizzle.swift b/ios/Shared/Swizzle.swift new file mode 100644 index 0000000000..6073384cf4 --- /dev/null +++ b/ios/Shared/Swizzle.swift @@ -0,0 +1,30 @@ +// +// Swizzle.swift +// MullvadVPN +// +// Created by pronebird on 28/10/2020. +// Copyright © 2020 Mullvad VPN AB. All rights reserved. +// + +import Foundation + +@inlinable func swizzleMethod(aClass: AnyClass, originalSelector: Selector, newSelector: Selector) { + guard let originalMethod = class_getInstanceMethod(aClass, originalSelector), + let newMethod = class_getInstanceMethod(aClass, newSelector) else { return } + + if class_addMethod( + aClass, + originalSelector, + method_getImplementation(newMethod), + method_getTypeEncoding(newMethod) + ) { + class_replaceMethod( + aClass, + newSelector, + method_getImplementation(originalMethod), + method_getTypeEncoding(originalMethod) + ) + } else { + method_exchangeImplementations(originalMethod, newMethod) + } +} |
