<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">
Hello evolutionists,<br class="">
<div class=""><br class="">
</div>
<div class="">As a domain specific languages designer, reflection is an essential feature for me, as it allows for embedded DSLs to easily handle user-defined types. Unfortunately I think Swift is quite behind regarding that point, in particular due to its
 inability to set properties discovered from a mirror (without resorting to the black magic of unsafe pointers). Before attempting to write a more formal proposal, I'd like to collect thoughts and opinions on the best way to extend Swift's reflection API so
 that it would support write capabilities.</div>
<div class=""><br class="">
</div>
<div class="">There are many points to address, but I have 2 open questions in particular I’d like to focus on:</div>
<div class=""><br class="">
</div>
<div class="">1. What would be the best way to provide a setter?</div>
<div class="">2. Should we care about the constantness of the properties (and/or their owning subjects)?</div>
<div class=""><br class="">
</div>
<div class="">Currently, one is able to introspect a particular subject that way:</div>
<div class=""><br class="">
</div>
<div class="">
<div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">
<span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">struct</span><span style="font-variant-ligatures: no-common-ligatures" class=""> Device {</span></div>
<div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">
<span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">enum</span><span style="font-variant-ligatures: no-common-ligatures" class=""> Kind {</span></div>
<div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">
<span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; </span>
<span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">case</span><span style="font-variant-ligatures: no-common-ligatures" class=""> phone, tablet</span></div>
<div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">
<span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; }</span></div>
<div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class="">
<span style="font-variant-ligatures: no-common-ligatures" class=""></span><br class="">
</div>
<div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">
<span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">let</span><span style="font-variant-ligatures: no-common-ligatures" class=""> kind:
</span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">Kind</span></div>
<div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">
<span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">var</span><span style="font-variant-ligatures: no-common-ligatures" class=""> modelName:
</span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">String</span></div>
<div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">
<span style="font-variant-ligatures: no-common-ligatures" class="">}</span></div>
<div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class="">
<span style="font-variant-ligatures: no-common-ligatures" class=""></span><br class="">
</div>
<div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">
<span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">var</span><span style="font-variant-ligatures: no-common-ligatures" class=""> iphone7 =
</span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">Device</span><span style="font-variant-ligatures: no-common-ligatures" class="">(kind: .</span><span style="font-variant-ligatures: no-common-ligatures; color: #31595d" class="">phone</span><span style="font-variant-ligatures: no-common-ligatures" class="">,
 modelName: </span><span style="font-variant-ligatures: no-common-ligatures; color: #d12f1b" class="">&quot;iPhone 7&quot;</span><span style="font-variant-ligatures: no-common-ligatures" class="">)</span></div>
<div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class="">
<span style="font-variant-ligatures: no-common-ligatures" class=""></span><br class="">
</div>
<div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">
<span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">var</span><span style="font-variant-ligatures: no-common-ligatures" class=""> mirror =
</span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Mirror</span><span style="font-variant-ligatures: no-common-ligatures" class="">(reflecting:
</span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">iphone7</span><span style="font-variant-ligatures: no-common-ligatures" class="">)</span></div>
<div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">
<span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">for</span><span style="font-variant-ligatures: no-common-ligatures" class=""> child
</span><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">in</span><span style="font-variant-ligatures: no-common-ligatures" class="">
</span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">mirror</span><span style="font-variant-ligatures: no-common-ligatures" class="">.</span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">children</span><span style="font-variant-ligatures: no-common-ligatures" class="">
 {</span></div>
<div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">
<span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #3e1e81" class="">print</span><span style="font-variant-ligatures: no-common-ligatures" class="">(</span><span style="font-variant-ligatures: no-common-ligatures; color: #d12f1b" class="">&quot;</span><span style="font-variant-ligatures: no-common-ligatures" class="">\</span><span style="font-variant-ligatures: no-common-ligatures; color: #d12f1b" class="">(</span><span style="font-variant-ligatures: no-common-ligatures" class="">child.label!</span><span style="font-variant-ligatures: no-common-ligatures; color: #d12f1b" class="">):
</span><span style="font-variant-ligatures: no-common-ligatures" class="">\</span><span style="font-variant-ligatures: no-common-ligatures; color: #d12f1b" class="">(</span><span style="font-variant-ligatures: no-common-ligatures" class="">child.value</span><span style="font-variant-ligatures: no-common-ligatures; color: #d12f1b" class="">)&quot;</span><span style="font-variant-ligatures: no-common-ligatures" class="">)</span></div>
<div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">
<span style="font-variant-ligatures: no-common-ligatures" class="">}</span></div>
<div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class="">
<span style="font-variant-ligatures: no-common-ligatures" class=""></span><br class="">
</div>
<div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0);" class="">
<span style="font-variant-ligatures: no-common-ligatures" class="">// Prints &quot;kind: phone&quot;</span></div>
<div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0);" class="">
<span style="font-variant-ligatures: no-common-ligatures" class="">// Prints &quot;modelName: iPhone 7&quot;</span></div>
</div>
<div class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><br class="">
</span></div>
<div class="">However, it is not possible to set the value of a property using reflection. `Mirror.Child` is a mere alias to `(String?, Any)`, and the mirror itself doesn't have any method that would achieve that.</div>
<div class=""><br class="">
</div>
<div class=""><br class="">
</div>
<div class=""><b class="">First question: what would be the best way to provide a setter?</b></div>
<div class=""><br class="">
</div>
<div class="">One solution would be to get inspiration from other reflection APIs (like that of Java for instance) and to modify the type of `Mirror.Child` so that it'd be a struct that has knowledge of its owning object. Then it could have a `set` method that
 would change the value of the property it reflects (note that for the time being I ignore the fact that `kind` is a let constant):</div>
<div class=""><br class="">
</div>
<div class=""><span style="color: rgb(0, 132, 0); font-family: Menlo; font-size: 11px;" class="">// Rough idea of how the type alias would be replaced ...</span></div>
<div class="">
<div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">
<span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">struct</span><span style="font-variant-ligatures: no-common-ligatures" class=""> MirrorChild {</span></div>
<div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">
<span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; label: String?</span></div>
<div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">
<span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; value: </span>
<span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">Any</span></div>
<div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">
<span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">mutating</span><span style="font-variant-ligatures: no-common-ligatures" class="">
</span><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">func</span><span style="font-variant-ligatures: no-common-ligatures" class=""> set(</span><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">_</span><span style="font-variant-ligatures: no-common-ligatures" class="">
 newValue: </span><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">Any</span><span style="font-variant-ligatures: no-common-ligatures" class="">)
</span><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">throws</span><span style="font-variant-ligatures: no-common-ligatures" class=""> {
</span><span style="font-variant-ligatures: no-common-ligatures; color: #008400" class="">/* ... */</span><span style="font-variant-ligatures: no-common-ligatures" class=""> }</span></div>
<div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">
<span style="font-variant-ligatures: no-common-ligatures" class="">}</span></div>
<div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class="">
<span style="font-variant-ligatures: no-common-ligatures" class=""></span><br class="">
</div>
<div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">
<span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">if</span><span style="font-variant-ligatures: no-common-ligatures" class="">
</span><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">var</span><span style="font-variant-ligatures: no-common-ligatures" class=""> kindProperty = mirror.children.first() {</span></div>
<div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">
<span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">try</span><span style="font-variant-ligatures: no-common-ligatures" class=""> prop.set(value: Device.Kind.tablet)</span></div>
<div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">
<span style="font-variant-ligatures: no-common-ligatures" class="">}</span></div>
</div>
<div class=""><br class="">
</div>
<div class="">Note that in the following example, I made `set` a throwing function because the type of the argument is it given may not agree with that of the property. This is because I kept `MirrorChild` as close as possible to the original type alias. However,
 if it was a struct, it might be clever to use a generic:</div>
<div class=""><br class="">
</div>
<div class="">
<div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">
<span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">struct</span><span style="font-variant-ligatures: no-common-ligatures" class=""> MirrorChild&lt;T&gt; {</span></div>
<div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">
<span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; label: String?</span></div>
<div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">
<span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; value: T</span></div>
<div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">
<span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">mutating</span><span style="font-variant-ligatures: no-common-ligatures" class="">
</span><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">func</span><span style="font-variant-ligatures: no-common-ligatures" class=""> set(</span><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">_</span><span style="font-variant-ligatures: no-common-ligatures" class="">
 newValue: </span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">T</span><span style="font-variant-ligatures: no-common-ligatures" class="">) {
</span><span style="font-variant-ligatures: no-common-ligatures; color: #008400" class="">/* ... */</span><span style="font-variant-ligatures: no-common-ligatures" class=""> }</span></div>
<div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">
<span style="font-variant-ligatures: no-common-ligatures" class="">}</span></div>
</div>
<div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">
<span style="font-variant-ligatures: no-common-ligatures" class=""><br class="">
</span></div>
<div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">This&nbsp;approach</span>&nbsp;might be problematic when the owning object is a value type (like in my example) for the child instance to have
 a “reference” on its owning subject. I guess this could be handled by some internal black pointer magic, or we could push the `set` function in the mirror type. Then the target child would be specified using its label or its index (in cases the label doesn’t
 exists, e.g. in collections):</div>
<div style="margin: 0px; line-height: normal;" class=""><br class="">
</div>
<div style="margin: 0px; line-height: normal;" class="">
<div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">
<span style="font-variant-ligatures: no-common-ligatures" class="">mirror.children[</span><span style="font-variant-ligatures: no-common-ligatures; color: #d12f1b" class="">&quot;kind”</span><span style="font-variant-ligatures: no-common-ligatures" class="">]?.value
 = Device.Kind.tablet</span></div>
</div>
<div class=""><br class="">
</div>
<div class="">Unfortunately, if I think this approach would work for almost all kind of subject, it wouldn't for enumerations. First, as far as I know, it is currently not possible to know which is the case of a reflected enumeration. Cases with associated
 values however are reflected by a mirror whose children contain a child labeled with the name of the case, and whose values are the associated values:</div>
<div class=""><br class="">
</div>
<div class="">
<div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">
<span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">enum</span><span style="font-variant-ligatures: no-common-ligatures" class=""> Nat {</span></div>
<div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">
<span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">case</span><span style="font-variant-ligatures: no-common-ligatures" class=""> zero</span></div>
<div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">
<span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">indirect</span><span style="font-variant-ligatures: no-common-ligatures" class="">
</span><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">case</span><span style="font-variant-ligatures: no-common-ligatures" class=""> succ(</span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">Nat</span><span style="font-variant-ligatures: no-common-ligatures" class="">)</span></div>
<div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">
<span style="font-variant-ligatures: no-common-ligatures" class="">}</span></div>
<div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class="">
<span style="font-variant-ligatures: no-common-ligatures" class=""></span><br class="">
</div>
<div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">
<span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">if</span><span style="font-variant-ligatures: no-common-ligatures" class="">
</span><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">let</span><span style="font-variant-ligatures: no-common-ligatures" class=""> child =
</span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Mirror</span><span style="font-variant-ligatures: no-common-ligatures" class="">(reflecting:
</span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">Nat</span><span style="font-variant-ligatures: no-common-ligatures" class="">.</span><span style="font-variant-ligatures: no-common-ligatures; color: #31595d" class="">succ</span><span style="font-variant-ligatures: no-common-ligatures" class="">(</span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">Nat</span><span style="font-variant-ligatures: no-common-ligatures" class="">.</span><span style="font-variant-ligatures: no-common-ligatures; color: #31595d" class="">zero</span><span style="font-variant-ligatures: no-common-ligatures" class="">)).</span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">children</span><span style="font-variant-ligatures: no-common-ligatures" class="">.</span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">first</span><span style="font-variant-ligatures: no-common-ligatures" class="">
 {</span></div>
<div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">
<span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #3e1e81" class="">print</span><span style="font-variant-ligatures: no-common-ligatures" class="">(child)</span></div>
<div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">
<span style="font-variant-ligatures: no-common-ligatures" class="">}</span></div>
<div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class="">
<span style="font-variant-ligatures: no-common-ligatures" class=""></span><br class="">
</div>
<div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0);" class="">
<span style="font-variant-ligatures: no-common-ligatures" class="">// Prints &quot;(Optional(&quot;succ&quot;), Nat.zero)&quot;</span></div>
</div>
<div class=""><br class="">
</div>
<div class="">Second, implementing a `set` method for mirror children wouldn't allow us to change the case of an enum, but only its associated values. One idea would be to sightly change how enum cases are represented, in a fashion closer to how dictionary
 entries are represented:</div>
<div class=""><br class="">
</div>
<div class="">
<div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">
<span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">if</span><span style="font-variant-ligatures: no-common-ligatures" class="">
</span><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">let</span><span style="font-variant-ligatures: no-common-ligatures" class=""> child =
</span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Mirror</span><span style="font-variant-ligatures: no-common-ligatures" class="">(reflecting: Nat.zero).children.first {</span></div>
<div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">
<span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; print(child)</span></div>
<div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">
<span style="font-variant-ligatures: no-common-ligatures" class="">}</span></div>
<div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0);" class="">
<span style="font-variant-ligatures: no-common-ligatures" class="">// Prints &quot;(nil, (&quot;zero&quot;, nil)&quot;</span></div>
<div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class="">
<span style="font-variant-ligatures: no-common-ligatures" class=""></span><br class="">
</div>
<div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">
<span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">if</span><span style="font-variant-ligatures: no-common-ligatures" class="">
</span><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">let</span><span style="font-variant-ligatures: no-common-ligatures" class=""> child =
</span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Mirror</span><span style="font-variant-ligatures: no-common-ligatures" class="">(reflecting: Nat.succ(Nat.zero)).children.first {</span></div>
<div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">
<span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; print(child)</span></div>
<div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">
<span style="font-variant-ligatures: no-common-ligatures" class="">}</span></div>
<div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0);" class="">
<span style="font-variant-ligatures: no-common-ligatures" class="">// Prints &quot;(nil, (&quot;succ&quot;, (Nat.zero)))&quot;</span></div>
</div>
<div class=""><br class="">
</div>
<div class="">The label would be replaced by the nil optional, and the value would be a tuple whose first element is the case name, and second element an optional tuple containing the associated values (i.e. `(String, Any?)`).</div>
<div class=""><br class="">
</div>
<div class="">A more elaborated solution would involve adding a kind of `PropertyDescription` type, that would allow to get/set the value of a property on a given instance. I think this approach would require more changes in the API reflection, which is why
 I‘d prefer the first I proposed.</div>
<div class=""><br class="">
</div>
<div class=""><br class="">
</div>
<div class=""><b class="">Second question: should we care about the constantness of the properties?</b></div>
<div class=""><br class="">
</div>
<div class="">In the example I gave above, I didn't care about the fact that `kind` is a let property of `Device`. As far as I know, it is currently not possible to know if a given child of a mirror is a let or var property. It doesn't really matter for read-only
 reflection, but might for write reflection.</div>
<div class=""><br class="">
</div>
<div class="">As originally a Python programmer, I wouldn't have much problem saying that it's the programmer's responsibility to ensure she/he doesn't break invariants when using reflection (all Python programmers are `__dict__` dirty hackers in their heart).
 However, I guess this position may very well not be shared, and may also very well not be applicable in a statically optimized language. Unfortunately, my knowledge of Swift's compiler isn't sufficient to know the slightest about the implications of such design
 choice.</div>
<div class=""><br class="">
</div>
<div class="">The same question could be asked for subjects that are let constants. Would `iphone7` be a let constant in my example, would it make sense to allow *any* of its properties to be modified via reflection?</div>
<div class=""><br class="">
</div>
<div class=""><br class="">
</div>
<div class="">Thanks a lot if you made it that far!</div>
<div class="">I’m looking forward to your reactions about this.</div>
<div class=""><br class="">
</div>
<div class="">Best regards,</div>
<div class="">Dimitri Racordon</div>
<div class=""><br class="">
</div>
</body>
</html>