<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 Sep 22, 2016, at 10:08 PM, Will Stanton via swift-dev <<a href="mailto:swift-dev@swift.org" class="">swift-dev@swift.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div class="">Hello,<br class=""><br class="">I had a question about the intended behavior/functionality of mirrors in Swift/Swift Foundation types.<br class=""><br class="">In general, should a Mirror reference all variables in a type? <br class="">I’m not sure what scope mirrors should/will have, but it does seem like some of iterating through children has been done:<br class=""><a href="http://stackoverflow.com/questions/34601802/how-can-i-check-if-a-property-has-been-set-using-swift-reflection" class="">http://stackoverflow.com/questions/34601802/how-can-i-check-if-a-property-has-been-set-using-swift-reflection</a><br class=""><br class="">Should mirrors only reference public+ variables? Or private ones too? Is it meant to be up to the author?<br class=""><br class=""></div></div></blockquote><div><br class=""></div><div>There exists a default behavior, but also an override mechanism (CustomReflectable) in case the author of the type knows better</div><div><br class=""></div><div>For instance, if you have</div><div><br class=""></div><div>struct Point { var x: Double; var y: Double }</div><div><br class=""></div><div>you probably do just want to see "x" and "y" reflected - and the default will do just that</div><div><br class=""></div><div>But in more complex scenarios, e.g. Array<T>, you probably want to see the logical contents of the type (the array elements), not the underlying implementation details</div><div><br class=""></div><div>I don't think metadata currently vends visibility, so it's unlikely we do anything to hide non-public variables in reflection.</div><div>I think other languages take a similar stance, so maybe it's just the right thing to do, but I also can't recall any explicit discussion about this</div><div><br class=""></div><div>As for the Foundation-specific bits, I'll let somebody with more Foundation expertise help you out</div><br class=""><blockquote type="cite" class=""><div class=""><div class=""><br class="">With respect to Foundation, I was starting to silence some warnings with ‘as Any’ (<a href="https://bugs.swift.org/browse/SR-2737" class="">https://bugs.swift.org/browse/SR-2737</a>), but I noticed this code in URLComponents.swift at <a href="https://github.com/apple/swift-corelibs-foundation/blob/master/Foundation/URLComponents.swift#L313:" class="">https://github.com/apple/swift-corelibs-foundation/blob/master/Foundation/URLComponents.swift#L313:</a><br class=""><br class="">if let s = self.scheme { c.append((label: "scheme", value: s)) }<br class="">if let u = self.user { c.append((label: "user", value: u)) }<br class="">etc...<br class=""><br class=""><br class="">Should public properties be mirrored even if their values are nil?<br class="">c.append((label: "scheme", value: s as Any))<br class="">c.append((label: "user", value: u as Any))<br class="">etc...<br class=""><br class="">What rules should there be to determine what gets mirrored?<br class=""><br class="">Regards,<br class="">Will Stanton<br class=""><br class="">_______________________________________________<br class="">swift-dev mailing list<br class=""><a href="mailto:swift-dev@swift.org" class="">swift-dev@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-dev<br class=""></div></div></blockquote></div><br class=""><div class="">
<div class="" style="color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 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;"><br class="Apple-interchange-newline">Thanks,</div><div class="" style="color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 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;"><i class="">- Enrico</i><br class="">📩 egranata@<font color="#ff2600" class=""></font>.com ☎️ 27683</div>
</div>
<br class=""></body></html>