<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=""><br class=""><div><blockquote type="cite" class=""><div class="">On May 26, 2016, at 9:25 PM, Austin Zheng via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div style="font-family: Helvetica; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">```</div><div style="font-family: Helvetica; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">myPerson.typedReadWriteProperty<Int>("age")?.set(30)</div><div style="font-family: Helvetica; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><br class=""></div><div style="font-family: Helvetica; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">try myPerson.allNamedProperties["age"]?.set(30)</div><div style="font-family: Helvetica; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">```</div><br class="Apple-interchange-newline"></div></blockquote></div><br class=""><div class="">Can you elaborate on what this API would be used for? KVC? For instance, I played with Mirror the other day and my code to get a value given the property name looked more like this:</div><div class=""><br class=""></div><div class="">let age = myPerson.value(forKey:”age”) as! Int</div><div class=""><br class=""></div><div class="">And this is what I did:</div><div class=""><br class=""></div><div class="">// KVC stands for key-value-coding… but I only know how to get values. I don’t know how to set values</div><div class=""><br class=""></div><div class=""><div class="">protocol KVC {</div><div class=""> func value(forKey key: String) -> Any!</div><div class="">}</div><div class=""><br class=""></div><div class="">// Default implementation</div><div class="">extension KVC {</div><div class=""> func value(forKey key: String) -> Any! {</div><div class=""> let aMirror = Mirror(reflecting:self)</div><div class=""> for case let (label?, value) in aMirror.children {</div><div class=""> if label == key {</div><div class=""> return value</div><div class=""> }</div><div class=""> }</div><div class=""> return nil</div><div class=""> }</div><div class="">}</div><div class=""><br class=""></div><div class="">public struct Person : KVC {</div><div class=""> let firstName: String</div><div class=""> let lastName: String</div><div class=""> let age: Int</div><div class=""><br class=""></div><div class=""> func fullName() -> String {</div><div class=""> return "\(firstName) \(lastName)"</div><div class=""> }</div><div class="">}</div><div class=""><br class=""></div><div class="">let aPerson = Person(firstName:"John", lastName:"Doe", age:48)</div><div class=""><br class=""></div><div class="">// It works for stored properties</div><div class="">let lastName = aPerson.value(forKey:"lastName") as! String</div><div class="">print("Last name is \(lastName)")</div><div class=""><br class=""></div><div class="">// It does not work for instance methods, i.e. fullName is not a stored property</div><div class="">let fullName = aPerson.value(forKey:"fullName")</div><div class="">if fullName != nil {</div><div class=""> print("Full name is \(fullName)")</div><div class="">} else {</div><div class=""> print("Unable to get fullName via KVC")</div><div class="">}</div></div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div></body></html>