How to suppress a specific warning in Swift
At present (Xcode 7.1), there seems to be no way of suppressing a specific warning in Swift (see e.g. How to silence a warning in swift).
In your special case, you can fool the compiler by
computing the number of bytes in a word:
func f() -> Int {
switch (__WORDSIZE / CHAR_BIT) { // Or: switch (sizeof(Int.self))
case 4: return 1
case 8: return 2
default: return 0
}
}
This compiles without warnings on both 32-bit and 64-bit architectures.
How to silence a warning in Swift?
As of 2021, Xcode 13.0, the consensus is that there is no way to achieve that.
I'll update/edit this answer if Apple add the feature.
Put it in your wish list for WWDC 2022 !
How to suppress warnings in Swift 3?
EDIT: below instruction is for "deprecated declarations" warning. If you want to suppress different warnings then you should use flag relevant for the warning. Most of you probably use Clang, and it's warning flags can be found here. So if you want to suppress for example -Wunused-argument
you will write it with "no": -Wnounused-argument
.
If you want to disable compiler warnings then go to Project -> Target -> Build Settings and add flag with no prefix to other warning flags:
If you want to disable warnings for separate file:
Go to Project and pick relevant Target -> Build Phases -> Compile Sources and flag separate file:
In Xcode, how to suppress all warnings in specific source files?
Select your target and show Build Phases. Then enter the name of the file in the search box, and you should see it listed in the Compile Sources phase. Double-click in the Compiler Flags column for that file and enter -w
to turn off all warnings for that file.
Xcode: suppressing all warnings for all external libraries
Quick Fix
I see you are using cocoapods.
Cocoapods rewrite your configs each time you run pod install
. So, you need to add this line in your podfile
to ignore all warnings or warnings for a specific pod:
# example to ignore all warnings from all pods
inhibit_all_warnings!
# example to ignore warnings from a specific pod
pod 'Alamofire', :inhibit_warnings => true
NOTE: Sometimes it is good to see your warnings and your pod's warnings too, so you could prevent issues in the future.
Removing warnings
Add @discardableResult to your function.
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
neglectable()
}
@discardableResult func neglectable() -> String {
return ""
}
}
Suppress Swift compiler warning
You can avoid the warning if the method signature will look like:
public func expect<T>(expression: (() -> T?), file: String = __FILE__, line: UInt = __LINE__) -> Expectation<T>
added extra parenthesis around the first argument, tested with Swift 2.0 and Xcode 7.1
Another way of fixing it is to have all attributes with default value before the closure attribute as trailing closure is a quite convenient thing to have
Related Topics
How Does Let X Where X.Hassuffix("Pepper") Work
Cllocation Distancefromlocation (In Swift)
Safari App Extension Crashes After a Few Seconds for Hello World Project
How to Migrate Core Data's Data to App Group's Data
Swiftui Sheet Not Updating Variable
Ios/Tvos Playground Fails with "Unable to Find Execution Service for Selected Run Destination"
How to Immediately See Swift Errors in Appcode
Swift Combine Publishers VS Completion Handler and When to Cancel
Using @Fetchrequest(Entity: ) for Swiftui MACos App Crashes
How to Override Private Method and Call Super in Swift
From Any Utf-16 Offset, Find the Corresponding String.Index That Lies on a Character Boundary
In Swift, Can You Find All Types in a Module That Adhere to a Specific Protocol
Core Data: Rename Attribute Without Having Issues with Users and Their Current Data
Create JSON Object from Class in Swift
Reflection with Swift - Get Functions Name of a Class
Generate Avaudiopcmbuffer with Avaudiorecorder
Realitykit - Load Another Scene from the Same Reality Composer Project