How can you make the target products platform specific in swift package manager
Define a dummy wrapper target that has platform dependent dependencies.
Here's an example excerpt from https://github.com/firebase/firebase-ios-sdk/blob/master/Package.swift that defines FirebaseDynamicLinks as only available on iOS, but not tvOS, macOS, or watchOS:
.library(
name: "FirebaseDynamicLinks",
targets: ["FirebaseDynamicLinksTarget"]
),
.
.
.
.target(
name: "FirebaseDynamicLinksTarget",
dependencies: [.target(name: "FirebaseDynamicLinks",
condition: .when(platforms: [.iOS]))],
path: "SwiftPM-PlatformExclude/FirebaseDynamicLinksWrap"
),
.target(
name: "FirebaseDynamicLinks",
....
Add dependencies to binary targets in Swift Package Manager
I think the real issue here is that the dependencies don't need to be a part of your modules's public interface. You would need to replace all instances of import
for the dependencies in your code to @_implementationOnly import
E.g.
@_implementationOnly import CocoaLumberjack
You can read more about @_implementationOnly
here
Sharing code across test targets when using the Swift Package Manager
I faced the same issue and solved it by defining a Target (not Test Target) instead for Common
.
My Package.swift
file:
// ...
.target(name: "Common", dependencies: ["App"], path: "Tests/Common"),
.testTarget(name: "AppTests", dependencies: ["App", "Common"]),
.testTarget(name: "IntegrationTests", dependencies: ["App", "Common"])
// ...
Related Topics
Convert Character to Integer in Swift
Swift 4.2 Setter Getter, All Paths Through This Function Will Call Itself
Swift String Interpolation Displaying Optional
Adding Local Dependencies in Xcode11 Using Spm
Parsing a Iso8601 String to Date in Swift
Getting String Name of Objective-C @Objc Enum Value in Swift
How to Cache Images Using Urlsession in Swift
Swift 3: Convert a Null-Terminated Unsafepointer<Uint8> to a String
Swift 5.5: Asynchronously Iterating Line-By-Line Through a File
Swiftui Customized Text Field in Osx
Invalid Update: Invalid Number of Items in Section 0
How to Send Data from iPhone to Watchkit in Swift
Select Filtered Search Results
Swift: How to Assign a Variable by Reference, Not by Value
Cannot Assign to Property: Function Call Returns Immutable Value