Avatar
こんな感じか? struct If<Then: View, Else: View>: ViewModifier { var condition: () -> Bool var `then`: (Content) -> Then var `else`: (Content) -> Else func body(content: Content) -> some View { if (condition()) { self.then(content) } else { self.else(content) } } } extension View { func `if`<Then: View, Else: View>( _ condition: @escaping @autoclosure () -> Bool, then: @escaping (If<Then, Else>.Content) -> Then, else: @escaping (If<Then, Else>.Content) -> Else ) -> some View { modifier(If(condition: condition, then: `then`, else: `else`)) } } (edited)