title: Is it possible to add Button<Text> to Text in SwiftUI?
body: <p>Normally, adding two Text views will produce a single Text view retaining the properties of each individual Text view. For example:</p>
  
  <pre class="lang-swift prettyprint-override"><code>Text(“Hello ”) + Text(“world!”).foregroundColor(.blue)
  </code></pre>
  
  <p>This should produce <code>Hello world!</code>, with <code>world!</code> in blue. Now, what should I do if I want <code>world!</code> to be tappable and act as a button? Well, logically it would make sense to do this:</p>
  
  <pre class="lang-swift prettyprint-override"><code>Text(“Hello ”) + Button(action: {}) { Text(“world!”).foregroundColor(.blue) }
  </code></pre>
  
  <p>However, the code directly above does not compile. Is it possible to create Text views with tappable portions as described? My use cas is for Tweets with <code>@</code> mentions or <code>#</code> hashtags where you would tap on either the mention or the hashtag to be shown a detail view.</p>
  
  <p><strong>EDIT:</strong> The reason why using a Text view and a Button in an HStack is unsuitable is because this is within a function which returns a Text view for the content of a tweet:</p>
  
  <pre><code>func styledText(text: String) -&gt; Text {
      var output = Text("")
      let components = text.tokenize("@#. ")
      for component in components {
          if component.rangeOfCharacter(from: CharacterSet(charactersIn: "@#")) != nil {
              output = output + Text(component).foregroundColor(.accentColor)
          } else {
              output = output + Text(component)
          }
      }
      return output
  }
  </code></pre>
  
  <p>Where <code>String.tokenize</code> is the following:</p>
  
  <pre class="lang-swift prettyprint-override"><code>extension String {
      func tokenize(_ delimiters: String) -&gt; [String] {
          var output = [String]()
          var buffer = ""
          for char in self {
              if delimiters.contains(char) {
                  output.append(buffer)
                  buffer = String(char)
              } else {
                  buffer += String(char)
              }
          }
          output.append(buffer)
          return output
      }
  }
  </code></pre>
  
  <p><strong>EDIT 2:</strong> If it helps, I'm trying to create a SwiftUI version of this: <a href="https://github.com/optonaut/ActiveLabel.swift" rel="noreferrer">https://github.com/optonaut/ActiveLabel.swift</a>.</p>