title: Optional @ViewBuilder closure
body: <p>Is it possible in SwiftUI to have an optional <code>@ViewBuilder</code> closure? For example, let's say I want to develop a custom view that takes two view builder closures like this:</p>
  
  <pre><code>import SwiftUI
  
  struct TopAndBottomView&lt;Content&gt;: View where Content: View {
      let topContent: () -&gt; Content
      let bottomContent: () -&gt; Content
  
      init(@ViewBuilder topContent: @escaping () -&gt; Content, @ViewBuilder bottomContent: @escaping () -&gt; Content) {
          self.topContent = topContent
          self.bottomContent = bottomContent
      }
  
      var body: some View {
          VStack {
              topContent()
              Spacer()
              bottomContent()
          }
      }
  }
  
  struct TopAndBottomView_Previews: PreviewProvider {
      static var previews: some View {
          TopAndBottomView(topContent: {
              Text("TOP")
          }, bottomContent: {
              Text("BOTTOM")
          })
      }
  }
  </code></pre>
  
  <p>But I'd like the bottom view to be optional. I tried with:</p>
  
  <pre><code>struct TopAndBottomView&lt;Content&gt;: View where Content: View {
      let topContent: () -&gt; Content
      let bottomContent: (() -&gt; Content)?
  
      init(@ViewBuilder topContent: @escaping () -&gt; Content, @ViewBuilder bottomContent: (() -&gt; Content)? = nil) {
          self.topContent = topContent
          self.bottomContent = bottomContent
      }
  
      var body: some View {
          VStack {
              topContent()
              Spacer()
              if bottomContent != nil {
                  bottomContent!()
              }
          }
      }
  }
  </code></pre>
  
  <p>but I get this error:</p>
  
  <blockquote>
    <p>Function builder attribute 'ViewBuilder' can only be applied to a
    parameter of function type.</p>
  </blockquote>
  
  <p>Thanks.</p>