konrad
konrad

Reputation: 1724

Xcode 8.2 Playground not showing UIKit results

I try to run some UIKit playground examples and I have problem viewing the graphic results.

What works:

  1. I can preview any string assignments in the grey right editor pane.
  2. I can click on the 'eye' (quick preview) or 'small rect' icons and see correct UIKit result albeit in a temporary popup or in a pane between the code lines (both smaller).
  3. I can print stuff and it shows in the pane below the editors (below the bar with timeline and start/stop button).

What does not work:

  1. I can't get large graphical display of my code results to display.

Below is some sample code I try to use:

import UIKit
import PlaygroundSupport

let containerView = UIView(frame: CGRect(x: 0.0, y: 0.0, width: 375.0, height: 667.0))


let circle = UIView(frame: CGRect(x: 0.0, y: 0.0, width: 50.0, height: 50.0))
circle.center = containerView.center
circle.layer.cornerRadius = 25.0

let button = UIButton(type: .detailDisclosure)
containerView.addSubview(button)

let startingColor = UIColor(red: (253.0/255.0), green: (159.0/255.0), blue: (47.0/255.0), alpha: 1.0)
circle.backgroundColor = startingColor

containerView.addSubview(circle);

PlaygroundPage.current.liveView = containerView

Is there anything more I should do run the playground? There's a related question: Playground not showing results where OP is asked if he set the device in the simulator. Well, in my case I didn't but I don't know where to do it. The simulator is not running.

EDIT:

I've seen the question marked as possible duplicate with accepted answer not working for me and the other one mentioning partial solution (only quick and inline previews). So to rephrase my question: In Xcode 8.2 should I expect to see UIView related results anywhere else than in quick preview (popup) and inline preview (between lines of code)?

Upvotes: 3

Views: 2266

Answers (3)

Ocunidee
Ocunidee

Reputation: 1809

I've had the same issue as you. Here is how I somehow solved it.

It seems that to have the live preview (PlaygroundPage.current.liveView), the playground is starting a simulator. In my case, it was opening an iOS 9 device by default. I guess it was the last one I had used.

  1. I closed the assistant editor of the playground, hid any inline previews I had (they seem to clash with the live preview) and then closed Xcode fully.
  2. In simulator -> Hardware -> Device, I chose an iOS 10 device enter image description here
  3. I closed the simulator as well
  4. I opened Xcode from the dock (not the file directly)
  5. I chose the playground to open
  6. I opened the assistant editor. At the top where you usually see the loader with "Running YourPlaygroundName", you should see "Launching the simulator". It should launch the iOS 10 device you chose above.

Hope it works for you

Upvotes: 4

Eddev
Eddev

Reputation: 900

Try if this works:

On the top right hand side, unclick any other buttons and press the below blue highlighted button. Xcode meny bar

Do you see the graphical view now?

Upvotes: 2

Acrasia
Acrasia

Reputation: 201

You should define what you mean by "large graphical display". Why the solution used in the link (and by you) doesn't match your needs ?

EDIT

screen

Is not a large graphical display ?

Upvotes: 0

Related Questions