I know that I should use @discardableResult. So I have the following code:
@discardableResult func someFunc() { ... }
Then I just call it:
someFunc()
But if I have and use a pointer to this method then it doesn't work again. For example:
let someFunc = self.someFunc
someFunc() //unused warning
Is it possible to avoid _=someFunc() in this case?
Unfortunately,
discardableResultonly applies to method/function declarations. What you can do is to wrap the value-returning function in a void-returning closure:Alternatively, write a function that "erases" the return type of functions:
The downside is that you need to write an overload of this for each arity: