title: Data conflicts - Swift
body: <p>I am new to Swift, and I am fetching a VPN certificate from a database to create a tunnel.
  The problem is that the variable that should contain the certificate (as Data type) is calling a function that is fetching the certificate, but the certificate takes time to appear, so the variable is empty and sent to the VPN configuration, so the VPN won't work.</p>
  <p>The certificate appears later on.</p>
  <p>I am not really good at solving these kinds of issues,
  I tried to make a delay in the function that is fetching my certificate, but the problem is still present (I know that it's a bad method because network speed may vary and I cannot control the time)</p>
  <p>Can you please help me?</p>
  <pre><code>func getCertificate() -&gt; Data? {
      self.loading.onNext(true)
      var configData:String = &quot;&quot;
      
      Services.getCert(authToken: UserManager.currentUser?.token ?? &quot;&quot;, method: vpnMethod, userID: String(UserManager.currentUser?.user_id ?? 0)) { (error, VpnModel, Int) in
          self.loading.onNext(false)
          
          if error == nil{
              if VpnModel?.cert_body == nil{
                  configData = &quot;&quot;
              }else{
                  configData = VpnModel?.cert_body ?? &quot;&quot;
              }
          }
      }
      
      let configurationData = Data(configData.utf8)
      print(String(decoding: configurationData, as: UTF8.self))
      return configurationData
  }
  </code></pre>