I'm using the Nimble assertion framework for unit testing in Swift (Xcode 6.3 beta). It works fine, but the compiler gives a warning for one of the lines in the Nimble source code:
public func expect<T>(expression: () -> T?, file: String = __FILE__, line: UInt = __LINE__) -> Expectation<T> {
return Expectation(
expression: Expression(
expression: expression,
location: SourceLocation(file: file, line: line),
isClosure: true))
}
The warning is for the first line:
Closure parameter prior to parameters with default arguments will not be treated as a trailing closure
It's not a very serious issue, but I'd like to keep the number of compiler warnings low (zero) in my projects. Is there a way to remove this warning?
If you want to disable all warnings, you can pass the -suppress-warnings flag (or turn on "Suppress Warnings" under "Swift Compiler - Warning Policies" in Xcode build settings).
Select your project and select your target and show Build Phases . Search the name of the file in which you want to hide, 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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With