Does “let _ = …” (let underscore equal) have any use in Swift?

前端 未结 6 1460
野性不改
野性不改 2020-12-11 02:50

Does using let _ = ... have any purpose at all?

I\'ve seen question and answers for What's the _ underscore representative of in Swift References? a

6条回答
  •  -上瘾入骨i
    2020-12-11 03:34

    You will get a compiler warning if the method has been marked with a warn_unused_result from the developer documentation:

    Apply this attribute to a method or function declaration to have the compiler emit a warning when the method or function is called without using its result.

    You can use this attribute to provide a warning message about incorrect usage of a nonmutating method that has a mutating counterpart.

提交回复
热议问题