なぜ?
従来のボタンの処理がみづらい。
全てのボタンの処理を一括で管理するために実験的にアプリに導入してみた。
一般的なボタンの使い方
 Button(action: {
            print("タップされたよ")
        }){
            Text("Tap me")
                .foregroundColor(Color.white)
                .frame(width: 200, height:200)
                .background(Color.red)
                .frame(width: 500, height: 500)
        }
今回の方法 (View.onButtonTap {})
Viewを拡張 + ViewModifierを使うことで行数を減らすことができ、アプリのボタンタップの処理を一括して管理できる。
struct ButtonTapModifier: ViewModifier {
    
    var onTapped: (() -> Void)?
    func body(content: Content) -> some View {
        Button(action: {
            self.onTapped?()
        }){
            content
        }
    }
}
extension View {
    public func onButtonTap(_ onTapped: (() -> Void)? = nil) -> some View {
        self.modifier(ButtonTapModifier(onTapped: onTapped))
    }
}
struct ContentView: View {
    var body: some View {
        Text("テスト")
            .foregroundColor(Color.white)
            .frame(width: 200, height:200)
            .background(Color.red)
            .onButtonTap {
                print("タップされたよ");
            }
            .frame(width: 500, height: 500)
    }
}