[swift-corelibs-dev] Mirror behavior

Will Stanton willstanton1 at yahoo.com
Fri Sep 23 00:08:48 CDT 2016


I had a question about the intended behavior/functionality of mirrors in Swift/Swift Foundation types.

In general, should a Mirror reference all variables in a type? 
I’m not sure what scope mirrors should/will have, but it does seem like some of iterating through children has been done:

Should mirrors only reference public+ variables? Or private ones too? Is it meant to be up to the author?

With respect to Foundation, I was starting to silence some warnings with ‘as Any’ (https://bugs.swift.org/browse/SR-2737), but I noticed this code in URLComponents.swift at https://github.com/apple/swift-corelibs-foundation/blob/master/Foundation/URLComponents.swift#L313:

if let s = self.scheme { c.append((label: "scheme", value: s)) }
if let u = self.user { c.append((label: "user", value: u)) }

Should public properties be mirrored even if their values are nil?
c.append((label: "scheme", value: s as Any))
c.append((label: "user", value: u as Any))

What rules should there be to determine what gets mirrored?

Will Stanton

More information about the swift-corelibs-dev mailing list