Reputation: 2347
We have designed a Swift Package that includes MapKit Extensions and some custom func
s that perform some Geographic computations. The intended usage would be to use a single Swift Package imported into Xcode to use two classes: one custom and the other extensions to MKMapView
.
Is it possible to create a single Swift Package that includes two or more target
s? How to properly update Package.swift
to support multiple targets?
import MapKitSwiftExtensions
import CustomGeospatialComputations
The impression is that a second target
in Package.swift
can be added in the targets
array.
.library(
name: "MapKit Swift Extensions",
targets: ["MapKitSwiftExtensions", "CustomGeospatialComputations"]
)
But when CustomGeospatialComputations
is added to the targets
array, I get this error š“:
target 'CustomGeospatialComputations' referenced in product 'MapKit Swift Extensions' could not be found
Ideally, I would like to have this file structure for development.
.
āāā Package.swift
āāā README.md
āāā Sources
āĀ Ā āāā CustomGeospatialComputations
āĀ Ā āāā GeoComputations.swift
āĀ Ā āāā MapKitSwiftExtensions
āĀ Ā āāā MKMapView+Extensions.swift
This is the Package.swift
that works (without CustomGeospatialComputations
)
// swift-tools-version:5.2
import PackageDescription
let package = Package(
name: "MapKit Swift Extensions",
products: [
.library(
name: "MapKit Swift Extensions"],
targets: ["MapboxSwiftExtensions"),
],
dependencies: [ ],
targets: [
.target(
name: "MapKitSwiftExtensions",
dependencies: []),
]
)
Upvotes: 5
Views: 3099
Reputation: 11494
Based on the error message, I'm pretty sure you're forgetting to define the CustomGeospatialComputations
target in your manifest's targets
array. Your complete manifest should look like this:
// swift-tools-version:5.2
import PackageDescription
let package = Package(
name: "MapKit Swift Extensions",
products: [
.library(
name: "MapKit Swift Extensions",
// Add the targets to your product.
targets: ["MapKitSwiftExtensions", "CustomGeospatialComputations"]),
],
dependencies: [ ],
targets: [
.target(
name: "MapKitSwiftExtensions",
dependencies: []),
// Define the target for the package.
.target(
name: "CustomGeospatialComputations",
dependencies: []),
]
)
Upvotes: 5