Hello everyone,
TL;DR: Does any of you know a way how to get
Quick Look working for
structs in Xcode? I managed to get it working only for
classes with
@objc binding.
A few weeks ago I saw
this tweet from Jeremy Howard praising
TensorSensor Python library. I really liked the diagrams of tensor shapes the library provides and I also vaguely knew about the Quick Look (aka the eye icon) feature in Xcode debugger. Quick Look allows one to have a visual representation of custom types during debugging. It can, for example, show images, bezier paths, UI views and more. My idea was to display a tensor shape diagram after clicking the "eye" icon on a
Tensor variable.
Also, I wanted to learn SwiftUI and implementing a view for visualization of tensors is a great excuse to finally do it. So I connected the dots and wrote a small view that can visualize Tensors in a similar fashion as TensorSensor. It all went smoothly except for the very last step described below.
Here is the GitHub repo and this is an example app:
So the next logical step in the implementation is to have a little tensor thumbnail show up whenever you click the "eye" Quick Look icon in Xcode. And ideally do the same thing in Xcode Playgrounds. And that's the part of the story where the things go off the rails...
Despite banging my head on the keyboard the last few nights I wasn't able to figure out a way to make Xcode run the debugQuickLookObject() method on a struct. And unfortunately Tensor is a struct. There are good reasons for it so changing it makes no sense.
Xcode documentation is a bit sparse. But to my best knowledge there's nothing explicitly requiring the Quick Look-able object to be a class. However, my knowledge of Swift and Xcode has big gaps so I figured I'll ask here and see if anyone would know a trick to get it to work.
Here's an issue that has a few more details and an example code.
Thanks for any comments and help!
Cheers,
Vojta