Mixing CocoaPods with Swift package - ios

I have an iOS project, that is divided into various frameworks using Swift packages. Now I need to create another swift package, which would include:
Some dependencies from other swift packages
Other dependencies from CocoaPods (GoogleMLKit/ObjectDetectionCustom to be exact)
How can I do this? Is there some way to import cocoa pod into the swift package?
For now, I implemented all this new functionality inside the main iOS app project, but I really don't like this solution. I would love to have this in a separate package.

You could perhaps include the GoogleMLKit/ObjectDetectionCustom package (if there is one) inside the package you are importing into your main project
For example I use Reachability package inside my own package which I then include in my main project

Related

Is it possible for Xcode to distinguish a cocoapod and swift package of the same name?

For example, when I use Alamofire, I can import it as a cocoapod or as a swift package. If I did both and include "import Alamofire", I found that it prefers to use the swift package module and not the pod module. This happens regardless of what version of Alamofire I've imported from both cocoapods or swift packages.
Is there a way to tell Xcode in the import statement to prefer a particular version of the module? Version as in release version, or some way to distinguish the package manager/pod vs swift package?
The use case for this is if multiple modules and dependencies are switching to swift package manager, and some dependencies make that switch at different times, or include overlapping dependencies with the main application.

Reference a CocoaPod from a local Swift Package

I have an Xcode 11 iOS project where I have created a local Swift Package for some basic services.
I have also added CocoaPod support where I am using a CocoaPod (SwiftEntryKit) for some UI stuff in the main project (not the Swift Package) which works fine.
Now I would like to reference a new CocoaPod (SwifterSwift) from within the local Swift Package itself. Is this possible? It does not have access to the SwiftEntryKit Pod I am already using in the main project - if I import it, it does not know the modules.
If you cannot reference Cocoapods from a Swift Package it makes the package rather limiting.
Thanks.

Package.swift together with Xcode 11 Project, how to use Carthage and SPM alongside?

I feel caught between the Carthage world and the Swift Package Manager (SPM) world, like being stuck in purgatory.
I'm developing a Swift library/SDK, and up until now, I've been using Carthage for dependencies. But since SPM finally works with iOS, I feel it would be great for people who want to use this library to be able to include it via SPM.
However, I've hit a wall. One of my dependencies, namely BitcoinKit works with Carthage but SPM support is broken.
In order to distribute my library, I need to have a Package.swift file, and some other critteria (README, source files in Sources, and tests in Tests). I also need to declare my dependencies in said Package.swift file, so that SPM recursivley can resolve all dependencies (when people install my library via SPM). Here's where I get stuck...
Since I'm still using Carthage I need a Xcode Project file to set up this Carthage dependency. But now my source files cannot import the SPM dependencies. They aren't found. Seems like I MUST include the SPM package dependencies using Xcode and Add Package Dependency feature (Apple doc here). This is not what I want right, I want my Package.swift file to declare the same versions of the SPM packages my library uses. To make it clear, this problem arises due to the fact that I need a Xcode project, due to Carthage.
So I thought maybe I could build BitcoinKit with Carthage (as I'm doing now), and include the built binary (.Carthage/Build/iOS/BitcoinKit.framework) my library, referencing it in Package.swift, but that does not work since SPM does not (yet?) support binaries (relevant Swift Forum Thread).
So what are my options?
1) Wait until someone smart fixes the broken SPM support in BitcoinKit (I've tried myself and failed), and then remove my Xcode project file and complete the transition of to only SPM and for now stick with Carthage...
2) Try to use SPM packages internally in my library installed through Xcode Add Package Dependency feature and manually sync those versions with the ones I declare in my Package.swift. Will that even work? Ugh, terrible solution anyway.
3) Hope to include BitcoinKit.framework built through Carthage as a binary when SPM supports it? When? Might take a while?
4) BitcoinKit also works with Cocoapods, but I guess that gets me nowhere, even worse actually, since Cocoapods creates a .xcworkspace file.
5) Wait until Apple hopefully (does anyone know if there are any plans?) changes so that we include Swift Packages via Package.swift file even when used together with an Xcode project file? That we I could keep on using Bitcoinkit via Carthage and only declare my SPM packages in one place and I guess SPM/Xcode/Swift would be responsible for integrating the dependencies into my Xcode project, but updated and managed through the Package.swift file...?
6) Any other alternative, real solution?
Without looking into the whole 'making bitcoinkit work with SPM' bit I think the 'linking a carthage prebuilt binary' idea sounds best as an interim solution at the very least.
It's not possible to link a binary in the package manifest (yet) but you can link it when you're building:
When building an SPM package from the command line using swift build you can link the binary using -Xswiftc or -Xlinker to pass the args -F path/to/bitcoinkit if you're linking a framework. Keep in mind each argument must have a cross argument flag before it.
When building in Xcode you should be able to solve it with an .xcconfig with the contents:
FRAMEWORK_SEARCH_PATHS = path/to/bitcoinkit
You may have to tweak it a bit but I imagine this should work, worst case having a separate .xcodeproj generated by swift package generate-xcodeproj --xcconfig-overrides myconfig.xcconfig.
There is a WalletExample in yenom/BitcoinKit on GitHub. It comes with a workspace and project.
I was able to include yenom/BitcoinKit with SPM in my Package.swift and I don't use any projects/workspaces.

How to use dynamic framework inside the pod?

I have a free framework (FW). It distributes via cocoapods. In this framework i use another framework. It compiled as dynamic framework (DFW).
So in my FW i need to write import DFW and after this can use it. Also the DFW is linked in Embedded Binaries and Linked Frameworks and Libraries in my project target.
After that i push my FW to cocoapods and after installing it tells Cannot find such a module near the import DFW statement.
The question is - how to properly distribute cocoapod with embedded dynamic frameworks in it?
There is no way to use dynamic frameworks in cocoapods, because it brings in a versioning issues. Instead of this use s.dependency in the podspec file. You can read this also.

Swift package manager for project migrated from Swift 2

I have a Swift 2 project, now converted to Swift 3. I was using HTMLKit pod, but the problem is that HTMLKit is no more on CocoaPods, but on swift package manager.
How can I add Swift Package Manager support to my existing project?
People say add dependency to package.swift but I have no such file in my project. How can I create this file?
Repositories under Swift Package Manager have certain layout. At the root of the repo you have Package.swift that provides a manifest for the repository, its name, type, dependencies, etc. You add it manually, just like any other source file.
However, before you do that please go through the documentation on SPM. It could help you to understand some specifics (like where do the dependencies end up in your repo once you check them out, how to arrange your own code so that SPM will handle it correctly, which folders to create, etc).

Resources