title: Change value in class with variable from For loop
body: <p>I have the following question about swift, let say I have an class like so:</p>
  
  <pre><code>class Person {
      var firstName, lastName, eyeColor: String
  
      init(firstName: String = "", lastName: String = "", eyeColor: String = "") {
          self.firstName = firstName
          self.lastName = lastName
          self.eyeColor = eyeColor
      }
  }
  </code></pre>
  
  <p>I could for example create a person like so:</p>
  
  <pre><code>var myFriend = Person(firstName: "Robin", eyeColor: "Yellow")
  </code></pre>
  
  <p>However as you can tell now I have not assigned a value to lastName aka this will be empty or "".</p>
  
  <p>What I want to do is iterate over all values in myFriend and check if one is empty, if thats true I would like it to replace the empty value with something like "No information".</p>
  
  <p>I did find something like</p>
  
  <pre><code>    let mirroredRecord = Mirror(reflecting: myFriend)
      for (index, attr) in mirroredRecord.children.enumerated() {
          if var value = attr.label as String? {
              if value == "" {
                  value = "No info"
              }
              print("Attr \(index): \(value) = \(attr.value)")
          }
      }
  </code></pre>
  
  <p>However that does not change the value in the myFriend variable.</p>
  
  <p>In my head the following seems logical but i'm unsure how to perform this action in swift.</p>
  
  <pre><code>for (index, attr) in mirroredRecord.children.enumerated() {
      if var value = attr.label as String? {
          if value == "" {
              myFriend.value = "No info"
          }
          print("Attr \(index): \(value) = \(attr.value)")
      }
  }
  </code></pre>
  
  <p>However because .value is not one of the options (firstName, lastName, eyeColor) it doesn't like it.</p>
  
  <p>Does anyone have any options or solutions regarding this?</p>