0

I am trying to create a dynamic framework project, I can use to inject code and for reverse engineering purposes.

I've been successfully able to inject code using Objective C file "(.m)" file.

#import <Foundation/Foundation.h>
#import "CodeInjection-Swift.h" // This line gives error.

@interface CodeInjection: NSObject
@end

@implementation CodeInjection

static void __attribute__((constructor)) initialize(void){
    NSLog(@"==== Code Injection in Action lolz====");
    [[CodeInjectionSwift shared] performTask];
}

@end

I also have a file called "CodeInjectionSwift.swift"

import Foundation
import NetworkInterceptor

@objc class CodeInjectionSwift: NSObject {
    @objc public static let shared = CodeInjectionSwift()

    override private init(){}

    @objc func performTask(){
        let requestSniffers: [RequestSniffer] = [
            RequestSniffer(requestEvaluator: AnyHttpRequestEvaluator(), handlers: [
                SniffableRequestHandlerRegistrable.console(logginMode: .nslog).requestHandler()
                ])
        ]

        let requestRedirectors: [RequestRedirector] = [
            RequestRedirector(requestEvaluator: DomainHttpRequestEvaluator(domain: "www.antennahouse.com"), redirectableRequestHandler: AlternateUrlRequestRedirector(url: URL(string: "https://www.rhodeshouse.ox.ac.uk/media/1002/sample-pdf-file.pdf")!))
        ]

        let networkConfig = NetworkInterceptorConfig(requestSniffers: requestSniffers,
                                                     requestRedirectors: requestRedirectors)
        NetworkInterceptor.shared.setup(config: networkConfig)
        NetworkInterceptor.shared.startRecording()
    }
}

If I get rid of the #import "CodeInjection-Swift.h" and the line [[CodeInjectionSwift shared] performTask];

The NSLog prints and am able to build successfully. I was told that I have to import -Swift.h file to use swift classes in CondeInjection-swift.h

Error message is

"-Swift.h not found"

enter image description here

My goal is to build the framework, and be able to utilize "CodeInjectionSwift" functionality that uses import NetworkInterceptor

Biplov
  • 1,136
  • 1
  • 20
  • 44
  • Possible duplicate of [How to access an internal Swift class in Objective-C within the same framework?](https://stackoverflow.com/questions/32700078/how-to-access-an-internal-swift-class-in-objective-c-within-the-same-framework) – Cristik Oct 05 '19 at 10:02
  • Seems you already posted a very similar question [here](https://stackoverflow.com/questions/58242172/not-able-to-import-project-name-swift-h-file-xcode), please don't post the same question multiple times. – Cristik Oct 05 '19 at 10:10

0 Answers0