3 ms·
Single-expression functions can now return a value without the “return” keyword: https://github.com/apple/swift-evolution/blob/master/proposals/0255-omit-return
by saagarjha 7y ago
Single-expression functions can now return a value without the “return” keyword: https://github.com/apple/swift-evolution/blob/master/proposals/0255-omit-return.md https://github.com/apple/swift-evolution/blob/master/proposa...
- laszlokorte 7y agoYeah but the example code looks like multiple expressions?
- saagarjha 7y agoThose might be functions that alter context of the closure rather than being returned. Or it might be some Swift compiler magic?
- skohan 7y agoThey look like initializers. Functions are lower-case by convention in Swift.
- saagarjha 7y agoThat is convention, but there’s no need to follow it ;)
- laszlokorte 7y agoSo far I found out it's implemented via parameter attribute [1] [1]: https://developer.apple.com/documentation/swiftui/viewbuilder https://developer.apple.com/documentation/swiftui/viewbuilde...
- saagarjha 7y agoOuch, that’s pretty awful…
- laszlokorte 7y agoMore details in the proposal [1]: > the basic idea is that we take the "ignored" expression results of a block of statements — including in nested positions like the bodies of if and switch statements — and build them into a single result value that becomes the return value of the current function. [1]: https://forums.swift.org/t/pitch-function-builders/25167 https://forums.swift.org/t/pitch-function-builders/25167