title: Pass @Published var by reference to function from View
body: <p>I am working on a registration screen which has a ViewModel attached to it.</p>
  <p>The ViewModel is just a class which extends my registration screen class, where I place all of my business logic.</p>
  <pre><code>extension RegistrationScreen {
      @MainActor class ViewModel : ObservableObject {
           //business logic goes here
      }
  }
  </code></pre>
  <p>The ViewModel has @Published variables to represent two states for every text field in the screen: text and validationText.</p>
  <pre><code> @Published var first: String = &quot;&quot;
   @Published var firstValidationMessage: String = &quot;&quot;
        
  </code></pre>
  <p>within that ViewModel I have a call to a helper function from another class which checks to see if the field's text is empty and if so it can set the fields validation text to an error, that looks like this:</p>
  <pre><code>class FieldValidation: Identifiable {
  
  
  func isFieldEmptyAndSetError(fieldText:String, fieldValidationText:Binding&lt;String&gt;) -&gt; Bool {
      
      if(fieldText.isEmpty){
          fieldValidationText.wrappedValue = &quot;Required&quot;
          return true
      }else{
          fieldValidationText.wrappedValue = &quot;&quot;
          return false
      }
  }
  }
  </code></pre>
  <p>to call that function from my viewModel I do the following:</p>
  <pre><code>FieldValidation().isFieldEmptyAndSetError(fieldText:first,fieldValidationText: firstValidationMessage)
  </code></pre>
  <p>This is throwing runtime errors which are hard to decrypt for me since I am new to Xcode and iOS in general.</p>
  <p>My question is, how can I get this passing by reference to work? alternatively if the way I am doing is not possible please explain what is going on.</p>