The @discardableResult Attribute in Swift

Gabriel Theodoropoulos
3 min readMar 19, 2021

Swift has several small features as a language, many of them being neglected quite often while they consist of small programming gems. One of them is the @discardableResult attribute that everybody wish they knew from the beginning.

What’s the purpose of @discardableResult? Put in simple words, when used to annotate a method, then the returned value of the method can be ignored when it gets

--

--

Gabriel Theodoropoulos

An iOS & macOS app maker writing code in Swift. Author of countless programming tutorials. Content creator. https://serialcoder.dev