I know that @discarableResult suppresses the warning when you don't use the return value when calling a function, but shouldn't it allow the function to be used in other cases where no return value is used?
For example, let's say I have a function that attempts an action and returns whether it succeeded, I would like to call it for each element in a list but this code doesn't compile:
@discardableResult
func attemptAction(with input: Int) -> Bool {
// ** attempt some action and determine whether it succeeded **
let succeeded = (input != 3)
return succeeded
}
let data = [1,2,3,4,5]
data.forEach(attemptAction) //ERROR: Cannot convert value of type '(Int) -> Bool' to expected argument type '(Int) -> Void'
I would expect the @discardableResult to express that the function can be used as `(Int) -> Bool` or as `(Int) -> Void` when the result is discarded.
I see this as an oversight and would like to report it to radar but I want to make sure I'm not missing something obvious before I do.
Thank you.