1 // Copyright 2015-present 650 Industries. All rights reserved.
2 
3 import Foundation
4 
5 class DevMenuUtils {
6   /**
7    Swizzles implementations of given selectors.
8    */
swizzlenull9   static func swizzle(selector selectorA: Selector, withSelector selectorB: Selector, forClass: AnyClass) {
10     if let methodA = class_getInstanceMethod(forClass, selectorA),
11       let methodB = class_getInstanceMethod(forClass, selectorB) {
12       let impA = method_getImplementation(methodA)
13       let argsTypeA = method_getTypeEncoding(methodA)
14 
15       let impB = method_getImplementation(methodB)
16       let argsTypeB = method_getTypeEncoding(methodB)
17 
18       if class_addMethod(forClass, selectorA, impB, argsTypeB) {
19         class_replaceMethod(forClass, selectorB, impA, argsTypeA)
20       } else {
21         method_exchangeImplementations(methodA, methodB)
22       }
23     }
24   }
25 
26   /**
27    Strips `RCT` prefix from given string.
28    */
stripRCTnull29   static func stripRCT(_ str: String) -> String {
30     return str.starts(with: "RCT") ? String(str.dropFirst(3)) : str
31   }
32 
resourcesBundlenull33   static func resourcesBundle() -> Bundle? {
34     let frameworkBundle = Bundle(for: DevMenuUtils.self)
35 
36     guard let resourcesBundleUrl = frameworkBundle.url(forResource: "EXDevMenu", withExtension: "bundle") else {
37       return nil
38     }
39     return Bundle(url: resourcesBundleUrl)
40   }
41 }
42