I use to swizzle main bundle with test bundle like follow in obj c
#import "NSBundle+Bundle.h"
#import <objc/runtime.h>
@implementation NSBundle (Bundle)
+(void)loadSwizzler {
static dispatch_once_t once_token;
dispatch_once(&once_token, ^{
Method originalMethod = class_getClassMethod(self, @selector(mainBundle));
Method extendedMethod = class_getClassMethod(self, @selector(bundleForTestTarget));
//swizzling mainBundle method with our own custom method
method_exchangeImplementations(originalMethod, extendedMethod);
});
}
//method for returning app Test target
+(NSBundle *)bundleForTestTarget {
NSBundle * bundle = [NSBundle bundleWithIdentifier:@"Philips.AppInfraTests"];
return bundle;
}
@end
But I tried the following for the same in swift
extension Bundle {
class func swizzle() {
let originalSelector = #selector(mainBundle)
let swizzledSelector = #selector(testBundle)
let originalMethod = class_getInstanceMethod(self, originalSelector)
let swizzledMethod = class_getInstanceMethod(self, swizzledSelector)
method_exchangeImplementations(originalMethod, swizzledMethod)
}
func mainBundle() -> Bundle
{
return Bundle.main
}
func testBundle() -> Bundle
{
return Bundle(for: self.classNamed("swizzler")!)
}
}
But this is throwing some errors "Argument of '#selector' cannot refer to variable 'testBundle'"
could some one help me how do I do it