title: How to use Combine on a SwiftUI View
body: <p>This question relates to this one: <a href="https://stackoverflow.com/questions/56735382/how-to-observe-a-textfield-value-with-swiftui-and-combine">How to observe a TextField value with SwiftUI and Combine?</a></p>
  
  <p>But what I am asking is a bit more general. 
  Here is my code:</p>
  
  <pre><code>struct MyPropertyStruct {
      var text: String
  }
  
  class TestModel : ObservableObject {
      @Published var myproperty = MyPropertyStruct(text: "initialText")
  
      func saveTextToFile(text: String) {
          print("this function saves text to file")
      }
  }
  
  struct ContentView: View {
      @ObservedObject var testModel = TestModel()
      var body: some View {
          TextField("", text: $testModel.myproperty.text)
      }
  }
  </code></pre>
  
  <p><strong>Scenario:</strong> As the user types into the textfield, the <em>saveTextToFile</em> function should be called. Since this is saving to a file, it should be slowed-down/throttled. </p>
  
  <p><strong>So My question is:</strong></p>
  
  <ol>
  <li>Where is the proper place to put the combine operations in the code below.</li>
  <li>What Combine code do I put to accomplish: <strong>(A)</strong> The string must not contain spaces. <strong>(B)</strong> The string must be 5 characters long. <strong>(C)</strong> The String must be debounced/slown down</li>
  </ol>
  
  <p>I wanted to use the response here to be a general pattern of: <em>How should we handle combine stuff in a SwiftUI app (not UIKit app).</em></p>