title: Android, Realm, Kotlin check RealmObject has field matching variable, set RealmObject key with variable
body: <p>So I have booleans in SharedPreferences in Android.</p>
  
  <p>I want to conditionally update the booleans in my Realm instance in the onPreferenceChanged listener. Some of the booleans are matched in the Realm Object, some are not.</p>
  
  <p>I would like to be able to see if the RealmObject has a key that matches the Preference Key and if so update the RealmObject with the Preference value.</p>
  
  <p>Here's the code</p>
  
  <pre><code>private val booleanBindPreferenceSummaryToValueListener = Preference.OnPreferenceChangeListener { preference, value -&gt;
  
      //log the preference change
      Log.d(TAG, "onBooleanPreferenceChanged: ${preference.key}: $value")
      //open the instance of Realm so we can update changes to the user object and have the information on the server
      val realm = Realm.getDefaultInstance()
      //get the userID from globals
      val userID = Globals.read("UserID", "")
      //make sure that the User ID is not null or blank
      if (!userID.isNullOrBlank()){
         //query the Realm database to get our instance of the user
         val user = realm.where&lt;User&gt;().equalTo("platformUserID", userID).findFirst()!!
         //find out if this particular boolean value is saved to the Realm object    
  
         //TO DO
  
      }
      realm.close()
      true
  
  }
  </code></pre>
  
  <p>In JavaScript I would just list the object keys and filter the array for any matches, then I would be able to write something like</p>
  
  <blockquote>
    <p>if (matches.some === true) User[preference.key] = preference.value</p>
  </blockquote>
  
  <p>I'm new to Kotlin but I thought this should be easy. It's eluding me at the moment.</p>