public required init<V>(
accessory: (() -> some View)? = nil as (() -> AnyView)?,
) {
self.accessory = { (accessory?()).flatMap(AnyView.init(erasing:)) }
}
In this scenario, the () around accessory?() is required. SwiftFormat's redundantParens rule removes them.
Without the parenthesis, the .flatMap operates on the result of the function (which is a non-optional View in this case), but instead it should operate on the optional result coming from the scenario where the function itself (the accessory closure) is nil.
$ swiftformat --version
0.52.2
$ cat .swift-version
5.8
$ swift --version
swift-driver version: 1.87.1 Apple Swift version 5.9 (swiftlang-5.9.0.128.2 clang-1500.0.40.1)
Target: arm64-apple-macosx14.0
Use case:
In this scenario, the
()
aroundaccessory?()
is required. SwiftFormat'sredundantParens
rule removes them.Without the parenthesis, the
.flatMap
operates on the result of the function (which is a non-optionalView
in this case), but instead it should operate on the optional result coming from the scenario where the function itself (theaccessory
closure) isnil
.