title: Cannot save data to realm
body: <p>I cannot seem to save data to realm in Swift! </p>
  
  <p>In one of my classes I have the following:</p>
  
  <pre><code>func getDeviceIdAndPersist(){
   print("getDeviceIdAndPersist")
   let realm = try! Realm()
   let realmWallet = RealmWallet()
   let realmResults = realm.objects(RealmWallet.self)
   for results in realmResults {
     guard results.deviceId != nil else {
       realmWallet.deviceId = NSUUID().UUIDString
       try! realm.write() {
         realm.add(realmWallet, update: true)
       }
      return
     }
   }
  }
  </code></pre>
  
  <p>And it does not seem to save the data! I have code similar to this throughout my application and its saving data but this isn't! </p>
  
  <p>Also I'm having trouble trying to persist my data, after i launch the application the data is stored using realm (which i can verify using the realm browser). However, once I re-launch the application the data no longer exists in realm! Does anyone have any suggestions as to why the data would not be persisted?</p>
  
  <p><strong>EDIT 1</strong></p>
  
  <p>Here is my realm class</p>
  
  <pre><code>class RealmWallet: Object {
    dynamic var publicKey = NSData()
    dynamic var preferredAddress = ""
    dynamic var id = 0
    let walletAddresses = List&lt;Addresses&gt;()
    dynamic var fee: NSNumber = 0.0
    dynamic var deviceId: String? = nil
    dynamic var tempPreTax: String? = nil
    dynamic var portalToken: String? = nil
    let walletHasBackup = RealmOptional&lt;Bool&gt;()
    let alreadyAskedForBluetooth = RealmOptional&lt;Bool&gt;()
    let insecureMailSent = RealmOptional&lt;Bool&gt;()
    let cameraAccessGranted = RealmOptional&lt;Bool&gt;()
    let idNowSuccess = RealmOptional&lt;Bool&gt;()
    dynamic var marketInfos = NSData()
  
  override class func primaryKey() -&gt; String? {
    return "id"
   }
  
  }
  </code></pre>
  
  <p><strong>EDIT 2</strong></p>
  
  <p>The NSUUID isn't the only data which I cannot save, the following is another example of data which I cannot seem to save using Realm:</p>
  
  <pre><code>onboardingModal!.bluetoothPressed = {() -&gt; Void in
   print("after onboardingModal")
    self.cbManager = CBCentralManager(delegate: self, queue: nil)
    print("REALM")
    let realm = try! Realm()
  
    do {
      try! realm.write {
        print("IN WRITE")
        self.realmWallet.alreadyAskedForBluetooth.value = true
        realm.add(self.realmWallet, update: true)
      }
    }
  }
  </code></pre>