Home > Back-end >  How should I pull in a vendored_framework into my project?
How should I pull in a vendored_framework into my project?

Time:01-22

I know how to package my code in the PodSpec. I'm using this post on how to publish my xcframework using cocoapods

Pod::Spec.new do |spec|
  spec.name               = "StarWars"
  spec.version            = "1.0.0"
  spec.summary            = "Star Wars Library for iOS apps"
  spec.description        = "..."
  spec.homepage           = "..."
  spec.documentation_url  = "..."
  spec.license            = { :type => "MIT" }
  spec.author             = { "Star Wars" => "..." }
  spec.source             = { :git => 'your repo here', :tag => "#{spec.version}" }
  spec.swift_version      = "5.3"

  # Supported deployment targets
  spec.ios.deployment_target  = "10.0"

  # Published binaries
  vendored_frameworks = "StarWarsKit.xcframework"
end

But the Podfile docs, don't mention how to decide between installing the source code vs the xcframework.

Like if I do:

pod 'StarWarKit', '~> 3.0'

How does that line above decide to either:

  • install the pre-built framework/binary itself
  • pull down the source code and then compile it into a framework and then install it.

How does it work then?

This other question, seems to bring up the same issue as a problem and mentions that you should use two PodSpecs. But it doesn't have an accepted answer and I'm wondering if either:

  • The problem still exists for CocoaPods
  • Newer versions of CocoaPods have ways to fix it.
  • Perhaps the blog post I used is wrong
  • Things work but under the hood you might be installing both the source and framework and that's probably not something good.

CodePudding user response:

I misread the PodSpec. I saw spec.source and just quickly assumed it's also pulling in source files.

However to pull in source files you'd have to do spec.source_files = 'Honey/common/**/*.swift'

Basically in the example above, you only end up pulling down the vendored_framework. No (source) files are pulled in directly.

The solution for to be able to distribute a binary and a source code is one that involves, not having them installed at the same time. For this there are two solutions:

  1. Have two distinct PodSpecs. See here. Make sure you also see the links inside.
  2. Have two SubSpecs. Along with having a default_subspecs. See here. With the approach you should never attempt to pull in both subspecs.
  • Related