No such module 'PackageDescription' in Xcode 11 - ios

I have an existing projects of a framework and library and would like them to use Swift Package Manager.
I have a Xcode 11 and have already already read Creating a Swift Package with Xcode.
After adding Package.swift to the project and an application target
import PackageDescription
let package = Package(
name: "MyLibrary",
platforms: [
.macOS(.v10_13),
],
products: [
.library(name: "MyLibrary", targets: ["MyLibrary"]),
],
dependencies: [
.package(url: "https://url/of/another/package/named/Utility", from: "1.0.0"),
],
targets: [
.target(name: "MyLibrary", dependencies: ["Utility"]),
.testTarget(name: "MyLibraryTests", dependencies: ["MyLibrary"]),
]
)
I get an error
No such module 'PackageDescription'
How can I import PackageDescription module?

I just added line below at the very first line of the Package.swift file and it worked for me.
// swift-tools-version:4.0
Note: Please do not write any thing even comment before this line
After that do not forget to run swift build command

Related

Suppress all warnings from my SPM package

Is there a way to suppress all warnings coming from my SPM Package in XCode?!
⚠️found 1 file(s) which are unhandled; explicitly declare them as
resources or exclude from the target
This warning shows because my SPM package contains .txt file.
I tried adding swiftSettings: [.unsafeFlags(["-suppress-warnings"])] in package.swift but didn't work.
// swift-tools-version:5.5
// The swift-tools-version declares the minimum version of Swift required to build this package.
import PackageDescription
let package = Package(
name: "Sourcery",
platforms: [.macOS(.v10_13)],
dependencies: [
.package(
url: "https://github.com/pointfreeco/swift-snapshot-testing.git",
from: "1.9.0"
)
],
targets: [
.executableTarget(
name: "Sourcery",
dependencies: []
),
.testTarget(
name: "SourceryTests",
dependencies: [.product(name: "SnapshotTesting", package: "swift-snapshot-testing")]
)
]
)
Looks like the exclude parameter supports folders as well. So I organized all .txt file in a folder and now I got rid of the warnings :)
import PackageDescription
let package = Package(
name: "Sourcery",
platforms: [.macOS(.v10_13)],
dependencies: [
.package(
url: "https://github.com/pointfreeco/swift-snapshot-testing.git",
from: "1.9.0"
)
],
targets: [
.executableTarget(
name: "Sourcery",
dependencies: [],
exclude: ["Templates"]
),
.testTarget(
name: "SourceryTests",
dependencies: [.product(name: "SnapshotTesting", package: "swift-snapshot-testing")],
exclude: ["__Snapshots__"]
)
]
)

Firebase [Swift Package Manager]: no such module FirebaseRemoteConfig

After I read the instructions listed here for how to add Firebase as a dependency to a Swift package, I couldn't get it to work, here's my Package.swift manifest:
import PackageDescription
let package = Package(
name: "MyPackage",
products: [
// Products define the executables and libraries a package produces, and make them visible to other packages.
.library(
name: "MyPackage",
targets: ["MyPackage"]),
],
dependencies: [
// Dependencies declare other packages that this package depends on.
.package(name: "Firebase",
url: "https://github.com/firebase/firebase-ios-sdk.git",
.upToNextMajor(from: "8.0.0"))
],
targets: [
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
// Targets can depend on other targets in this package, and on products in packages this package depends on.
.target(
name: "MyPackage",
dependencies: [.product(name: "FirebaseRemoteConfig", package: "Firebase")]),
.testTarget(
name: "MyPackageTests",
dependencies: ["MyPackage"]),
]
)
the package graph resolves without problems, but when I try to add my own code in Sources/MyPackage.swift starting with import FirebaseRemoteConfig the compiler complains with:
No such model 'FirebaseRemoteConfig'.
what's went wrong with my setup ?
I figured out the solution, but unfortunately it's not documented on Firebase Docs, I have to add the .platforms array in the Package.swift manifest specifying a version that supports FirebaseRemoteConfig, for example:
platforms: [
.iOS(.v13)
]

How to exclude dependency for Catalyst in Swift Package Manager?

There is an ios project with Catalyst included. The project has a YandexMobileMetrica dependency that cannot compile for mac architecture. How can I add an iOS-only dependency using Swift Package Manager?
I tried to do two targets. In the first spm-test, I disabled the mac flag. And in the second, spm-test-mac left. My Package.swift looks like this:
import PackageDescription
let package = Package(
name: "spm-test",
products: [
.library(
name: "spm-test",
targets: ["spm-test"]),
],
dependencies: [
.package(name: "YandexMobileMetrica", url: "https://github.com/yandexmobile/metrica-sdk-ios", from: "3.14.1"),
],
targets: [
.target(
name: "spm-test",
dependencies: ["YandexMobileMetrica"]),
.target(
name: "spm-test-mac",
dependencies: [])
]
)
Error:
AppDelegate.swift:11:12: No such module 'YandexMobileMetrica'
My AppDelegate.swift
// AppDelegate.swift
//
import UIKit
#if !targetEnvironment(macCatalyst)
import YandexMobileMetrica // 🛑 Error here
#endif

How do I declare the Siesta Swift package as a dependency of another Swift package?

I'm trying to use the Swift package Siesta as a dependency for the package I'm building and reference it in my package code. I've identified how to import the package into my project in my Package.swift file which is simple enough:
dependencies: [
.package(url: "https://github.com/bustoutsolutions/siesta", from: "1.5.1")
],
This causes the package to be copied into my package just fine. The problem I'm having is actually linking it up to my package so I can import it and reference it in code. I know I need to actually link it up to my target
I've read some other package files and because the package name for Siesta is like this
let package = Package(
name: "Siesta",
And the products it declares are like this
products: [
.library(name: "Siesta", targets: ["Siesta"]),
.library(name: "SiestaUI", targets: ["SiestaUI"]),
.library(name: "Siesta_Alamofire", targets: ["Siesta_Alamofire"]),
],
I should be able to just do this in my package file's target to use it
.target(
name: "MyTarget",
dependencies: [.product(name: "Siesta", package: "Siesta")]),
But when I try to build my package, I get an error:
/Users/blahblah/Desktop/MyPackage/Package.swift: unknown package 'Siesta' in dependencies of target 'MyTarget'
And not only that, all the targets for my single run scheme on my package go missing and I can't build again without discarding all my local version control changes. What's going on here?
With Swift tools version 5.2 you have to provide a name argument when declaring your package dependency.
.package(name: "Siesta", url: "https://github.com/bustoutsolutions/siesta", from: "1.5.1")
A working example of a Package.swift file:
// swift-tools-version:5.2
// The swift-tools-version declares the minimum version of Swift required to build this package.
import PackageDescription
let package = Package(
name: "MyPackage",
products: [
.library(
name: "MyLibrary",
targets: ["MyTarget"]),
],
dependencies: [
// make sure to provide a `name` argument here
.package(name: "Siesta", url: "https://github.com/bustoutsolutions/siesta", from: "1.5.1")
],
targets: [
.target(
name: "MyTarget",
dependencies: [
.product(name: "Siesta", package: "Siesta")
]),
]
)
Source: https://forums.swift.org/t/package-names-in-swift-5-2/34886/6

Add PostgreSQL to vapor project

I added .package(url: "https://github.com/vapor-community/postgresql-provider.git", .upToNextMajor(from: "2.1.0")) to my Package.swift file, ran vapor update and let it regenerate the Xcode project. When I then add the import of PostgreSQLProvider Xcode can't find it. I already have postgresql and pkg-config installed via homebrew.
I'm using Xcode 9 and Swift 4
Looks like you are using the Swift 4 package manager. The API for it was updated so you have to explicitly add the dependency to the target:
// swift-tools-version:4.0
import PackageDescription
let package = Package(
name: "Project",
products: [
.library(name: "App", targets: ["App"]),
.executable(name: "Run", targets: ["Run"])
],
dependencies: [
.package(url: "https://github.com/vapor/vapor.git", .upToNextMajor(from: "2.1.0")),
.package(url: "https://github.com/vapor/fluent-provider.git", .upToNextMajor(from: "1.2.0")),
.package(url: "https://github.com/vapor-community/postgresql-provider.git", .exact("2.1.0"))
],
targets: [
.target(name: "App", dependencies: ["Vapor", "FluentProvider", "PostgreSQLProvider"],
exclude: [
"Config",
"Public",
"Resources",
]),
.target(name: "Run", dependencies: ["App"]),
.testTarget(name: "AppTests", dependencies: ["App", "Testing"])
]
)
See above, I added the PostgreSQLProvider package to dependencies array for App target.
I had this problem too and wasn't sufficient with vapor xcode because it only regenerate the project and don't fetch the new dependencies like postgree you're adding, to solve this use vapor fetch and later vapor xcode, both commands with the project closed

Resources