Swift Package and `#if canImport(...)`. How does it work?
(Answer from experience in Apr 2020)
It looks like I'm just misunderstanding the compile order.
Importing my packaged module (let's call it CloudStorage
) declares a dependency in the client project to that module. Before the client project can compile with its other dependencies, CloudStorage
needs to compile without the main project's dependencies. Since CloudStorage
doesn't know anything about those dependencies, canImport
for those dependencies evaluates to false.
This may have changed in a later version of Swift. I've yet to try again.
how to add libxml2 as dependency to SwiftPM
I'm happy to say that this issue has now been fixed as of Xcode 11. All you need to do is import libxml2 just as you would any other module from the SDK such as Foundation or UIKit -- no additional search paths or configuration are needed.
For C targets you can also change the import style from #import <libxml2/libxml/.h> to just #import <libxml/.h> for compatibility with the more common header layout on Linux.
Swift/Xcode dependency management approach
Here is some points about each of them
1. CocoaPods
Pros
- Most widely used dependency manager.
- Almost every popular libraries, framework vendors provide pod for their library/framework.
- You can try the library and its usage without manually downloading it manually.
pod try
command
Cons
- You should manage your project with a workspace.
- If any vendor is not adding or updating their library's pod spec, it will be difficult to maintain.
2. Carthage
Pros
- No need to keep the project in a workspace.
- It's not a centralized system, that is no need to wait for the vendor to update/add the library to any centralized repo.
Cons
- Need to add your frameworks to project for the first time.
3. Swift Package Manager
Pros
Product from creators/maintainers of swift itself.
No extra workspace created.
Super easy to integrate.
ConsNot very popular.Still, need to be adopted by the developer community.
4. Manual
Pros
- You have full control.
- You can edit(if the license allows to..).
Cons
- Need manual work to add dependencies.
- Difficult to update libraries.
- Not sure whether we can add Objective-C libs to project using Swift Package Manager.
I would suggest using CocoaPods
because its very simple to use and will get enough help and resources from the internet.
In WWDC 2019, Apple introduced Xcode 11 with the built-in feature to use SPM. So it would be easy to use SPM as Cocoapods.
Setting up library with CocoaPods and Swift Package Manager
From @Larme's comment, I found the answer.
In your podspec file, change the location of your classes to the sources folder.
So changed my s.source_files from to BillboardSwiftLibrary/Classes/**/*
to Sources/**/*
and pod lib lint BillboardSwiftLibrary.podspec
worked fine.
Related Topics
Extract Reality Composer Scene for Arquicklook
Leaving Equal Width Gap Spacing Before and Between Menu Buttons
Load a Spritekit Scene from Another Bundle
Swiftui Change on Multilevel Children Published Object Change
Swift 3 Custom Extension of Ns Measurement? Ex. Sheeps to Goats
<Unknown>:0: Error: Opening Import File for Module 'swift': Not a Directory
Macos App Sandboxing - Read Access to Referenced Files from Parsed Xml
Changing a Label in Prepareforsegue
How to List All Available Patterns in a Scdynamicstorage
Add New Card Is Not Being Called in Stripe Paymentoptionviewcontroller
Swift Set UIbutton Setbordercolor in Storyboard
How to Build a Recursive Function in Swift to Return a String
Parse Codable Classes and Avoid Repetition
How to Calculate The Camera Position from Vuforia Gl Matrix
Calling Consecutive Animations in Swift with Completion Handler
List Scroll Freeze on Catalyst Navigationview
Swift Unsafemutablepointer & Unsafemutablepointer<Unsafepointer<Sometype>>