Custom QuickLooks meaningful inline previews to instances. For example, an abstract shape class might create a concrete geometric visualization. An address class might assemble a contact card. A player object might show its primary sprite.
These custom items are particularly useful in playgrounds, where you can use the eye-icon QuickLook pop-up to peek more closely at generated instances. Custom looks move beyond the default representations you get for free from classes like views and colors. They enable you to promote your implementations to first class playground participants.
Until Swift 2.0, you could add quick look support to any NSObject descendent by adding a debugQuickLookObject() function.
Swift 2.0’s standard library extends that support to all types through its CustomPlaygroundQuickLookable protocol. Declare conformance, implement customPlaygroundQuickLook() and return a member of the PlaygroundQuickLook (a QuickLookObject type alias) enumeration.
Supported enumerated items are:
case Text(String) case Int(Int64) case UInt(UInt64) case Float(Float32) case Double(Float64) case Image(Any) case Sound(Any) case Color(Any) case BezierPath(Any) case AttributedString(Any) case Rectangle(Float64, Float64, Float64, Float64) case Point(Float64, Float64) case Size(Float64, Float64) case Logical(Bool) case Range(UInt64, UInt64) case View(Any) case Sprite(Any) case URL(String)
Of course, upon seeing this list I had to try and see whether I could create a QuickLook Sound instance.
Sad, isn’t it?
Comments are closed.