children property on Mirror in Swift incorrect in iOS 14 beta 4
Originator: | raymccrae | ||
Number: | rdar://FB8297564 | Date Originated: | 8/7/20 |
Status: | Closed | Resolved: | Closed |
Product: | iOS | Product Version: | 14 beta 4 |
Classification: | Incorrect/Unexpected Behavior | Reproducible: | Yes |
I make use of the Reflection APIs in Swift for the development my app. Specifically to use the Mirror type to access the properties of structs and associated values on enums. Starting with Xcode 12.0 beta 4 (12A8179i) I have found that the children property on the Mirror type when reflecting a values was not returning the children as expected. My code iterates over the children using the method given in the code sample on https://developer.apple.com/documentation/swift/mirror/children of wrapping the children property in a AnyBidirectionalCollection. The children property with Xcode 12.0 beta 3 (12A8169g) gave the struct properties / enum associated values as expected. I have attached a playground file that demonstrates the issues as well as including the output on beta 3 and beta 4. **** Output of playground in Xcode 12.0 beta 3 (12A8169g) displayStyle: Optional(Swift.Mirror.DisplayStyle.struct) subjectType: Contact (label: Optional("name"), value: "Johnny Appleseed") (label: Optional("age"), value: 34) **** Output of playground in Xcode 12.0 beta 4 (12A8179i) displayStyle: Optional(Swift.Mirror.DisplayStyle.struct) subjectType: Contact no children **** Content of playground import UIKit func printReflection(_ value: Any) { let mirror = Mirror(reflecting: value) print("displayStyle: \(mirror.displayStyle.debugDescription)") print("subjectType: \(mirror.subjectType)") guard let children = AnyBidirectionalCollection(mirror.children), !children.isEmpty else { print("no children") return } for child in children { print(child) } } struct Contact { var name: String var age: Int } let c1 = Contact(name: "Johnny Appleseed", age: 34) printReflection(c1)
Comments
Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!
I've retested with Xcode 12 beta 5 (12A8189h). and the issues has been resolved.