---
title: "#139: Visualizing Results in Xcode Playgrounds 🎪📈"
url: https://littlebitesofcocoa.com/139-visualizing-results-in-xcode-playgrounds
author: Jake Marsh
date: 2015-12-03
published: 2015-12-03
topics: ["Playgrounds"]
description: "One of the most useful parts of Xcode Playgrounds is the way they allow us to visualize our code. We can click the Quick Look button, or insert a preview..."
---

# #139: Visualizing Results in Xcode Playgrounds 🎪📈

By Jake Marsh, December 3, 2015. HTML: https://littlebitesofcocoa.com/139-visualizing-results-in-xcode-playgrounds

One of the most useful parts of _Xcode Playgrounds_ is the way they allow us to visualize our code. We can click the **Quick Look** button, or insert a preview <i>directly into our code</i> with the **Show Result** button in the **Results sidebar**:

<img src='https://media.littlebitesofcocoa.com/bite-assets/139-visualizing-results-in-xcode-playgrounds-results-sidebar.png' style='max-width: 195px;' />

We can add visual representations to the **assistant timeline** using _XCPlayground's_ captureValue function ([Bite #136][1]).

[1]: https://littlebitesofcocoa.com/136

This can be incredibly handy for spotting problems quickly:

<img src='https://media.littlebitesofcocoa.com/bite-assets/139-visualizing-results-in-xcode-playgrounds-example.png' style='max-width: 383px;' />

Tons of system types are supported like **CGPath**, **NSURLs**, and even many of **SpriteKit's** classes. These are actually the same representations that can be seen if we **Quick Look** something while debugging in **Xcode**.

We can add these capabilities to our own custom **types** (for <i>both </i>debugging and<i> </i>_Playgrounds_) by adding a **function** like this to them, returning a supported type:

``` swift
func debugQuickLookObject() -> AnyObject? { return name }
```

This is great, but only works on types that inherit from **NSObject** and won't work for things like **Swift structs**. Also, even though we're adding this to our own type, we'll still need to return one of the built-in, Quick Look-able types supported by **Xcode**.

For more flexibility, let's look at _XCPlayground's_ **XCPlaygroundLiveViewable** protocol.

This will let us visualize our own **types** by returning a **view** or **view controller** that will be shown in the **assistant timeline** when we capture a value:

``` swift
extension Person : XCPlaygroundLiveViewable {
  func playgroundLiveViewRepresentation() -> XCPlaygroundLiveViewRepresentation {
    let vc = PersonLiveViewableViewController(person: self)
    return .ViewController(vc)
  }
}
```

Now, we can set our **current page's** `liveView` to a instance of Person <i>directly</i>, and we'll see our custom **view controller** appear in the **assistant timeline**. Neat!

``` swift
XCPlaygroundPage.currentPage.liveView = Person()
XCPlaygroundPage.currentPage.needsIndefiniteExecution = true
```
