title: Dynamic key property wrapper
body: <p>I have a simple property wrapper written to easily get and set user preferences in the UserDefaults.</p>
  <pre class="lang-swift prettyprint-override"><code>@propertyWrapper
  struct UserDefault&lt;Value&gt; {
      let key: String
      let defaultValue: Value
  
      var wrappedValue: Value {
          get { UserDefaults.standard.object(forKey: key) as? Value ?? defaultValue }
          set { UserDefaults.standard.set(newValue, forKey: key) }
      }
  }
  
  // Example usage
  @UserDefault(key: &quot;com.example.flag&quot;, defaultValue: false)
  var trackingEnabled: Bool
  </code></pre>
  <p>Now this works fine for static preferences, but say I were to support multiple users and each of them would be able to store their settings.</p>
  <pre class="lang-swift prettyprint-override"><code>struct Person {
      let id: UUID
      let name: String
  
      @UserDefault(key: &quot;com.example.person.\(id)&quot;, defaultValue: false)
      var trackingEnabled: Bool
  }
  </code></pre>
  <p>This gives me the warning <code>Cannot use instance member 'id' within property initializer; property initializers run before 'self' is available</code>. Is there a way to solve this so I can easily use this property wrapper with a dynamic key?</p>