iOS8: Custom Swift Framework accessing external framework written in Objective-C

前端 未结 3 1193
天涯浪人
天涯浪人 2021-01-05 00:58

I\'m trying to create a custom framework called CouchbaseKit (a new target in Xcode) in Swift. Inside my CouchbaseKit, I need to access Couc

相关标签:
3条回答
  • 2021-01-05 01:04

    Unfortunately Cocoapods 0.39 suffers from "Transitive Vendor Dynamic Libraries Unsupported" You'll see this with the newest couchbase-lite-ios release including the binary CouchbaseLite.framework. This unfortunately issue bit me so hard I had to refactor everything to use Carthage, and manually manage my frameworks in my final projects.

    Speaking of which the binary released CouchbaseLite.framework is simply missing a module map.

    Add one to: CouchbaseLite.framework/Modules/module.modulemap

    framework module CouchbaseLite {
      umbrella header "CouchbaseLite.h"
    
      export *
      module * { export * }
    }
    

    You will then be able to include this framework into a bridging header, and have your dynamic framework nest properly. But you might need to switch to building your CouchbaseKit.framework to using Carthage like I did.

    0 讨论(0)
  • 2021-01-05 01:09

    CouchbaseLite on iOS is a static framework, i.e. its binary is a static library not a dylib. This means it's linked into your app as though it were a source file. For this reason you don't use import in Swift to access it; the classes are already in the same namespace as your app's classes.

    0 讨论(0)
  • 2021-01-05 01:21

    If you still want to use Cocoapods you can follow this

    Steps:

    • Create a folder called the name of your Framework you want to use in that case CouchbaseLite and inside it create module map. The file name will be module.map and its content will be

    module CouchbaseLite { header "../Pods/couchbase-lite-ios/CouchbaseLite.framework/Headers/CouchbaseLite.h" export * }

    Important Note: Don't add that folder to the project, I don't know why not when done it will not work.

    • Import Paths under Swift Compiler – Search Paths in your project settings. Use ${SRCROOT} in the module path (e.g. ${SRCROOT}/CouchbaseLite) .

    • Then you can import it like any swift module.

    Update: It will work nicely in Xcode, but when I have tried to validate the pod with the pod lint it still give error and I still don't know why.

    0 讨论(0)
提交回复
热议问题