17

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 :

spec.vendored_frameworks = 'MyPod/Framework/MyFramework.framework'
spec.source_files = ['MyPod/UI/Views/MyView.{h,m}']

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 ?

mfaani
  • 33,269
  • 19
  • 164
  • 293
Drico
  • 1,284
  • 15
  • 33

4 Answers4

4

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' => 'mail@example.com' }
  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' => 'mail@example.com' }
  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
shocking
  • 848
  • 12
  • 16
1

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.

Ricowere
  • 707
  • 4
  • 7
  • Yes, but then, how do I access to MyFrameworks classes ? – Drico Mar 06 '17 at 15:12
  • Like you said, the `MyFramework` depencency is private. How do you want to access it from outside the pod? You said you only want to expose `MyView` to be open and this one relies on public headers from `MyFramework`. (By the way review your framework headers to make sure you allow access to it). – Ricowere Mar 06 '17 at 15:30
  • Only the sources of `MyFramework` are private. Moreover, I already access them without any trouble when not using `use_frameworks!` – Drico Mar 08 '17 at 11:14
0

Since the project's pods are now a framework, you could try importing it as a module using @importMyFramework.

However, if that doesn't work, then try backing up your project and then running pod deintegrate && pod install. Also, this question is very similar, and some of its comments and answers may be helpful.

Community
  • 1
  • 1
Coder-256
  • 5,212
  • 2
  • 23
  • 51
0

While shocking's answer is technically right there is a way to combine source_files and vendored_frameworks. The solution is to also use preserve_paths pointing to the location of the vendored frameworks.

Foti Dim
  • 1,303
  • 13
  • 19