I'm trying to create a custom framework called CouchbaseKit
(a new target in Xcode) in Swift. Inside my CouchbaseKit
, I need to access CouchBaseLite Framework
that's entirely written in Obj-C. I'm using Cocoapods
to manage CouchBaseLite
and a couple of other frameworks. Below is my podfile.
Podfile
# Uncomment this line to define a global platform for your project
link_with ['CouchbaseKit']
# platform :ios, '8.0'
use_frameworks!
target 'CouchbaseDB' do
link_with ['CouchbaseKit']
pod 'couchbase-lite-ios'
pod 'SwiftyJSON', '~> 2.2.0'
pod 'Alamofire', '~> 1.2'
pod 'XCGLogger', '~> 2.0'
end
target 'CouchbaseDBTests' do
end
target 'CouchbaseKit' do
end
target 'CouchbaseKitTests' do
end
Pods inside the project:
For my TARGETS I have the following settings in Build Phases.
Define Module Yes
Allow Non-modular Includes in Framework Modules Yes
Problem: When I try to access the CouchbaseLite framework inside my CouchbaseKit (my custom framework), I get an error, "No such module 'CouchbaseLite' does not exist.
Tried:
Since the project is in Swift, I created an Objective-C File and Hit yes to "Would you like to configure an Objective-C bridging header?"
Even though Allow Non-modular Includes in Framework Modules is set to YES in all targets, I still get an error when I try to #import <CouchbaseLite/CouchbaseLite.h>
in CouchbaseKit.h
Here is what my Build Phases looks like for my custom framework CouchbaseKit
Question: How can I see an external Objective-C framework (CouchasebaseLite) in my custom Swift framework?
Import Swift code into Objective-C within the same framework: Under Build Settings, in Packaging, make sure the Defines Module setting for that framework target is set to Yes. Import the Swift code from that framework target into any Objective-C .
You can use Objective-C and Swift files together in a single project, no matter which language the project used originally. This makes creating mixed-language app and framework targets as straightforward as creating an app or framework target written in a single language.
A framework is a modular and reusable set of code that is used as the building blocks of higher-level pieces of software. It is a bundle (Directory structure) that contains shared libraries as well as sub directories of headers and other resources.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With