29

Assuming I have a Package.swift like this below, and SomePackage from the dependencies produces warnings during swift build.

// swift-tools-version:4.0
import PackageDescription

let package = Package(
    name: "my-app",
    dependencies: [
        .package(url: "https://some-package.git", .upToNextMajor(from: "1.0"))
    ],
    targets: [
        .target(name: "Run", dependencies: ["SomePackage"]
    ]
)

How can I suppress those warnings from the dependencies, but keep the ones coming from my code?

1
  • I'm using a custom script based on CocoaPods' xcodeproj tool which I run after generating my Xcode project. See: gist.github.com/siemensikkema/57ef1ce3340e32b72dc59e44bc37b477 I adjust it to make exceptions for the frameworks that are generating warnings that I don't care about (in my case when working with Vapor 2). Commented May 29, 2018 at 14:43

4 Answers 4

11

With Swift Tools Version 5 you may define compiler flags in the package file (see https://docs.swift.org/package-manager/PackageDescription/PackageDescription.html#swiftsetting). Here is an example for a Package.swift which suppresses compiler warnings during build:

// swift-tools-version:5.0

import PackageDescription

let package = Package(
    name: "Antlr4",
    products: [
        .library(
            name: "Antlr4",
            targets: ["Antlr4"]),
    ],
    targets: [
        .target(
            name: "Antlr4",
            dependencies: [],
            swiftSettings: [
                .unsafeFlags(["-suppress-warnings"]),
            ]),
        .testTarget(
            name: "Antlr4Tests",
            dependencies: ["Antlr4"]),
    ]
)

To suppress warnings only in foreign code you should split the code into two packages.

Sign up to request clarification or add additional context in comments.

1 Comment

Tried this one out but didn't work for found 1 file(s) which are unhandled; explicitly declare them as resources or exclude from the target. XCode group those warnings as uncategorized can this be the reason why it doesn't work?
7

For Objective-C modules, you can use the following to disable all warnings:

cSettings: [
   .unsafeFlags(["-w"])
]

Comments

-4

I don't know how to suppress only dependencies warnings but it is possible to suppress all warnings during build by passing this option: -Xswiftc -suppress-warnings. The call will looks like

swift build -Xswiftc -suppress-warnings

3 Comments

Partway solution, like either get all warnings or get none. Thanks.
The question is how to suppress warnings on dependencies. So, the answer is not to suppress all warnings.
Actually something I was looking for. What would be the equivalent for xodeubild?
-7

If you are using an Xcode 10 project file:

  1. Click the project file in Xcode
  2. Select the target of your dependency
  3. Go to Build Settings
  4. Search for Swift Compiler - Warnings Policies
  5. Set the Suppress Warnings flags appropriately

2 Comments

In my opinion this way is the most correct and easy.
The question is how to suppress warnings on dependencies. So, the answer is not to suppress all warnings.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.