Apple's Swift document mentioned the discardableResult attribute in many places, for example:
discardableResult
Apply this attribute to a function or method declaration to suppress the compiler warning when the function or method that returns a value is called without using its result.
and
Because it’s not necessarily a mistake for code that calls the advance(to:) method to ignore the return value, this function is marked with the @discardableResult attribute.
Why would we have called a method if that method's return value is to be discarded? One of the situations where we call a method just to discard its return value is if that method, apart from calculating that return value, comes with some side effect.
网友评论