title: function doesn't return true unless I call it once before I need it
body: <p>I have a function called iCloudIsOn() which checks whether a user has opted to use iCloud with the app by comparing the value of a UserDefaults key with a predefined one, and then I am using this on my initial View Controller to sync iCloud and implement pull to refresh, but only if the user is using iCloud, otherwise this code is not needed.</p>
  
  <p>What's strange however is that the function only returns true if I call it right before I need to use it, even with just a print(iCloudIsOn())</p>
  
  <p>The function itself looks like this:</p>
  
  <pre><code>func iCloudIsOn() -&gt; Bool {    
      if UserDefaults.standard.url(forKey: "UDDocumentsPath") == iCloudPath { return true }
      else { return false }
  }
  </code></pre>
  
  <p>Then under viewDidLoad of my initial vc:</p>
  
  <pre><code>override func viewDidLoad() {
      super.viewDidLoad()
  
      if iCloudIsOn() {
          // sync iCloud
      }
  }
  </code></pre>
  
  <p>This will not work however and iCloudIsOn() will return false at that time unless I add a print(iCloudIsOn()) before if iCloudIsOn() { // sync iCloud }</p>
  
  <p>I tried asking iCloudIsOn to print both the value of the UserDefaults key and iCloudPath every time it is called and they are always identical: file:///private/var/mobile/Library/Mobile%20Documents/iCloud~cristian~thrive-storage/Documents/</p>
  
  <p>So there isn't something in my code changing the value for one of them at some point (the value is printed before the return).</p>
  
  <p>Any idea on why this is happening? Is it something to do with how UD works or am I missing something else? I find it a little strange, but I'm sure I'm just making a mistake somewhere.</p>
  
  <p>Thanks in advance.</p>