Import Objective-c framework into Swift framework (Google Analytics + Cocoapod)

后端 未结 3 720
一整个雨季
一整个雨季 2021-02-19 18:12

I\'m trying to centralize my commonly used Swift code into a framework, and part of that code uses Google Analytics. I brought in Google Analytics as a Cocoapod, but I can\'t a

3条回答
  •  既然无缘
    2021-02-19 18:41

    For those who have continued to ask if I had solved this problem, the following is how I accomplished this task importing the KochavaTracker SDK Cocoapod into a framework. That SDK is currently written in Objective-C. This answer is based on the answer provided by nuKs, with these specific steps.

    1) Create a folder named KochavaTracker under your project folder, i.e. MyFramework/MyFramework/KochavaTracker.

    2) Within that folder create a file named module.modulemap and insert the following content:

    /*
     This is the private module which is used to make private ObjC headers available to Swift code.
     Note how all header files need to be specified with paths relative to this file.
    
     This file lives inside a folder, and that folder is the actual module. In Xcode the SWIFT_INCLUDE_PATHS needs to include the parent directory to that folder.
     */
    module KochavaTracker {
        header "../../Pods/KochavaTrackeriOS/KochavaTrackeriOS/Classes/KochavaTracker.h"
        export *
    }
    

    This effectively creates a module which is a wrapper for interface of the SDK, which Swift can later import like it does other Swift modules. Note that it relies on a relative path to the Pods folder.

    3) As found in build settings, modify your SWIFT_INCLUDE_PATHS to include:

    $(SRCROOT)/KochavaTracker
    

    This makes it so that you will be able to import the module and it will locate it in/as the KochavaTracker folder which you created under it.

    4) Add to your Swift code, where appropriate:

    import KochavaTracker
    

    From there you should be able to reference the classes in the KochavaTracker module.

提交回复
热议问题