title: SwiftUI: How can I catch changing value from observed object when I execute function
body: <p>I have a problem with observed object in SwiftUI.
  I can see changing values of observed object on the View struct.
  However in class or function, even if I change text value of TextField(which is observable object) but "self.codeTwo.text still did not have changed.</p>
  
  <p>here's my code sample (this is my ObservableObject)</p>
  
  <pre><code>class settingCodeTwo: ObservableObject {
  
  private static let userDefaultTextKey = "textKey2"
  @Published var text: String = UserDefaults.standard.string(forKey: settingCodeTwo.userDefaultTextKey) ?? ""
  
  private var canc: AnyCancellable!
  
       init() {
          canc = $text.debounce(for: 0.2, scheduler: DispatchQueue.main).sink { newText in
          UserDefaults.standard.set(newText, forKey: settingCodeTwo.userDefaultTextKey)
  
      }
  }
  
  
     deinit {
       canc.cancel()
     }
  
  }
  </code></pre>
  
  <p>and the main problem is... "self.codeTwo.text" never changed!</p>
  
  <pre><code>class NetworkManager: ObservableObject {
  
  
  @ObservedObject var codeTwo = settingCodeTwo()
  @Published var posts = [Post]()
  
  
  func fetchData() {
      var urlComponents = URLComponents()
      urlComponents.scheme = "http"
  
  
  
      urlComponents.host = "\(self.codeTwo.text)" //This one I want to use observable object
  
  
  
  
      urlComponents.path = "/mob_json/mob_json.aspx"
      urlComponents.queryItems = [
          URLQueryItem(name: "nm_sp", value: "UP_MOB_CHECK_LOGIN"),
          URLQueryItem(name: "param", value: "1000|1000|\(Gpass.hahaha)")
      ]
  
      if let url = urlComponents.url {
          print(url)
          let session = URLSession(configuration: .default)
          let task = session.dataTask(with: url) { (data, response, error) in
              if error == nil {
                  let decoder = JSONDecoder()
                  if let safeData = data {
                      do {
                          let results = try decoder.decode(Results.self, from: safeData)
  
                          DispatchQueue.main.async {
                              self.posts = results.Table
                          }   
                      } catch {
                          print(error)
                      }
                  }
              }
          }
          task.resume()
      }
  
  }
  }
  </code></pre>
  
  <p>and this is view, I can catch change of the value in this one</p>
  
  <pre><code>import SwiftUI
  import Combine
  
  
  
  struct SettingView: View {
  
    @ObservedObject var codeTwo = settingCodeTwo()
    var body: some View {
      ZStack {
          Rectangle().foregroundColor(Color.white).edgesIgnoringSafeArea(.all).background(Color.white)
          VStack {
  
  
              TextField("test", text: $codeTwo.text).textFieldStyle(BottomLineTextFieldStyle()).foregroundColor(.blue)
  
              Text(codeTwo.text)
          }
      }
  }
  }
  </code></pre>
  
  <p>Help me please.</p>