Can anyone explain to me why this is happening? I seem to remember an explanation earlier in the book, but I can’t seem to find it. Thanks for any help.
Xcode’s playgrounds use something called a PlaygroundQuickLook
to present information in the results sidebar.
Currently, GreekGod
and Pantheon
don’t really have any good way to provide a description to the sidebar. Thus, it defaults to the expression that you’re seeing.
Conform to CustomPlaygroundQuickLookable
to provide more information to the results sidebar. For example,
extension GreekGod: CustomPlaygroundQuickLookable {
var customPlaygroundQuickLook: PlaygroundQuickLook {
let godMirror = Mirror(reflecting: self) // Provides an API to inspect an instance
let type = godMirror.subjectType // The type of the instance
return .text("\(type) named \(self.name)")
}
}
You should see the sidebar display something like "GreekGod named Hecate"
on this line: let hecate = GreekGod(name: "Hecate")
.
1 Like