title: UserDefaults is not saved with Swift
body: <p>I'm trying to use the UserDefaults to persistently save a boolean value. This is my code :</p>
  <pre><code>public static var isOffline = UserDefaults.standard.bool(forKey: &quot;isOffline&quot;) {
      didSet {
          print(&quot;Saving isOffline flag which is now \(isOffline)&quot;)
          UserDefaults.standard.set(isOffline, forKey: &quot;isOffline&quot;)
          UserDefaults.standard.synchronize()
      }
  }
  </code></pre>
  <p>Why doesn't work? What is the problem in this code?</p>
  <p>The problem is that when I try to retrieve <code>&quot;isOffline&quot;</code> key from <code>UserDefaults</code> I always get a <code>false</code>.</p>
  <p>I set the isOffline in the .onChange method of the row (I'm using Eureka as framework to create forms). The flag keep the right value during the lifecycle of the app, but when I close it that value is probably removed in some way.</p>