Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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:

  • I put a resource in the Resources directory.
  • I referenced the resource as UImage(named: "resource.jpg")

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

like image 345
Mickey Mouse Avatar asked Nov 09 '22 13:11

Mickey Mouse


1 Answers

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

like image 166
Jeff Avatar answered Nov 15 '22 07:11

Jeff