美文网首页
A Note on Attribute

A Note on Attribute

作者: 刘煌旭 | 来源:发表于2022-06-21 23:34 被阅读0次

    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.

    相关文章

      网友评论

          本文标题:A Note on Attribute

          本文链接:https://www.haomeiwen.com/subject/ozryvrtx.html