Mickey Mouse
Mickey Mouse

Reputation: 1771

UIImage not rendering in Xcode 6.3.1 Playground

I spent two hours trying to make this simple code to work, with no luck.

What I did:

This is not a duplicate question as the Playground settings went through a major change in 6.3.1

However, nothing is showing up. Here's a snapshot of my screen. As you can see there's no playground indicator running.

enter image description here

Upvotes: 5

Views: 1041

Answers (2)

Jeff
Jeff

Reputation: 4229

The biggest problem I see from your screenshot is that you don't even have the playground timeline open to see the results in the first place. The playground timeline is 1 column to the right of the playground gutter.

To view the playground timeline you use the Assistant Editor from the upper right. It is the button with the icon depicting 2 interconnected rings, or from the menu bar View > Assistant Editor > Show Assistant Editor.

assistant editor button

The second thing I figured out is that you have to put the UIImageView inside a regular UIView for the call to XCPShowView to work properly. See code below.

import UIKit
import XCPlayground

let image = UIImage(named: "pd.jpg")
let imageView = UIImageView(image: image)
XCPShowView("view", imageView) // Console error.

let bounds = imageView.bounds
let view = UIView(frame: bounds)
view.backgroundColor = UIColor.lightGrayColor()
view.addSubview(imageView)
XCPShowView("view", view) // This works!

Screen shot of the whole thing: playground screen shot

Upvotes: 1

Areal-17
Areal-17

Reputation: 406

For displaying an image in Playground you have to import XCPlayground.

import UIKit
import XCPlayground

Upvotes: 0

Related Questions