Xcode-beta (7A176x): Custom mirror ignored for CustomReflectable types
| Originator: | natecook | ||
| Number: | rdar://22353413 | Date Originated: | 19-Aug-2015 04:49 PM |
| Status: | Open | Resolved: | |
| Product: | Developer Tools | Product Version: | Xcode-beta (7A176x) |
| Classification: | Other Bug | Reproducible: | Always |
Summary:
The custom mirror is ignored for yes that conform to the CustomReflectable when using dump() or String(reflecting:). Creating a Mirror and iterating through the children shows the custom mirror correctly.
Steps to Reproduce:
1) Create a new playground.
2) Build a type Foo with two stored properties and one computed property, then add conformance to CustomReflectable. The custom mirror should contain all three properties as children:
struct Foo : CustomReflectable {
let a: Int
let b: String
var c: String {
return "\(a) - \(b)"
}
func customMirror() -> Mirror {
return Mirror(self, children: ["a": a, "b": b, "c": c])
}
}
2) Create an instance of Foo and try the different ways of reflecting on its contents:
let foo = Foo(a: 1, b: "Hi")
dump(foo)
print(String(reflecting: foo))
Mirror(reflecting: foo).children.forEach {
print("\($0!): \($1)")
}
Expected Results:
Each of the three methods should show three properties of foo:
▿ Foo
- a: 1
- b: Hi
- c: 1 - Hi
Foo(a: 1, b: "Hi”, c: “1 - Hi”)
a: 1
b: Hi
c: 1 - Hi
Actual Results:
Only the method using Mirror(…)… correctly displays the third property, c:
▿ Foo
- a: 1
- b: Hi
Foo(a: 1, b: "Hi")
a: 1
b: Hi
c: 1 - Hi
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!