I'm building a cocoapod that basically contains a framework (private sources) and a view (open source) that rely on this framework, all made in Objective-C.
In the podspec I have the following lines :
When using the use_frameworks!
syntax, I can't #import MyFramework
I just don't understand what's happening.
Moreover, when I remove the spec.source_files
line, I can #import MyFramework
and it works perfectly, but of course I cannot use MyView
.
What am I doing wrong ?
use_frameworks! in the Podfile means that we want the listed frameworks to be dynamically installed instead as static frameworks.
Create a Cocoa Touch Framework Xcode projectLaunch Xcode and create a new project, choose Cocoa Touch Framework . Enter the name SwiftyLib , select the checkbox Include Unit Tests . On the next page select the project location and do not check Create Git repository on my Mac as we are going to create it later on.
For anyone coming across this problem today: this is a known problem in CocoaPods, with a few issues raised on Github here and here discussing the problem.
The suggested workaround is to split your podspec into two: one podspec with only your vendored_frameworks
and another podspec with only the source_files
that use the framework.
User crsantos on Github has helpfully posted an example of this workaround, with two separate podspecs that I have reproduced below.
Vendored framework podspec:
# Regarding https://github.com/CocoaPods/CocoaPods/issues/6409
Pod::Spec.new do |s|
s.name = 'SampleDynamicLibPod'
s.version = '0.0.1'
s.summary = 'SampleDynamicLibPod. Cool Story bro!'
s.description = <<-DESC
Blah Blah Blah Blah Blah description
DESC
s.homepage = 'https://github.com/crsantos/SameRepoForAllPodSpecsAndSource'
s.license = { :type => 'MIT', :file => 'LICENSE' }
s.author = { 'Carlos Santos' => '[email protected]' }
s.source = { :git => 'https://github.com/crsantos/SameRepoForAllPodSpecsAndSource.git', :tag => "#{s.name}-#{s.version.to_s}" }
# this is the way of tagging diferent podspecs on the same repo
# Dont't forget to tag your repo with `SampleDynamicLibPod-0.0.1` for this specific spec
s.module_name = 'SampleDynamicLibPod'
s.ios.deployment_target = '9.0'
s.platform = :ios, '9.0'
s.pod_target_xcconfig = { 'SWIFT_VERSION' => '3' }
s.vendored_frameworks = 'SampleDynamicLibPod/Frameworks/SampleDynamicLib.framework'
end
Source files podspec. Note the dependency on the vendored framework podspec.
# Regarding https://github.com/CocoaPods/CocoaPods/issues/6409
Pod::Spec.new do |s|
s.name = 'WrapperAroundSampleDynamicLibPod'
s.version = '0.0.2' # just a different number to avoid confusion with the other podspec
s.summary = 'WrapperAroundSampleDynamicLibPod. Cool Story bro!'
s.description = <<-DESC
Wrapper Around Sample Dynamic Lib Pod Blah Blah Blah Blah Blah Blah Blah Blah
DESC
s.homepage = 'https://github.com/crsantos/SameRepoForAllPodSpecsAndSource'
s.license = { :type => 'MIT', :file => 'LICENSE' }
s.author = { 'Carlos Santos' => '[email protected]' }
s.source = { :git => 'https://github.com/crsantos/SameRepoForAllPodSpecsAndSource.git', :tag => "#{s.name}-#{s.version.to_s}" }
# Dont't forget to tag your repo with `WrapperAroundSampleDynamicLibPod-0.0.2` for this specific spec
s.module_name = 'WrapperAroundSampleDynamicLibPod'
s.ios.deployment_target = '9.0'
s.platform = :ios, '9.0'
s.pod_target_xcconfig = { 'SWIFT_VERSION' => '3' }
s.source_files = 'WrapperAroundSampleDynamicLibPod/Classes/**/*'
s.dependency 'CocoaLumberjack/Swift'
s.dependency 'SampleDynamicLibPod', '0.0.1' # you can achieve this with "#{s.name}-#{s.version.to_s}" from the
end
If you use use_frameworks!
your pod itself will become a framework. Therefore you should #import MyPod
instead of #import MyFramework
and then use MyView
.
Review also public_header_files
in case you need it.
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