3

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)?

Community
  • 1
  • 1
konrad
  • 1,664
  • 2
  • 17
  • 36
  • Possible duplicate of [iOS Playground doesn't show UI preview](http://stackoverflow.com/questions/33543460/ios-playground-doesnt-show-ui-preview) – Acrasia Feb 20 '17 at 15:54
  • Yeah, thanks, it probably is, but the solutions there are either working partially or not working at all. – konrad Feb 20 '17 at 16:10
  • 1
    FWIW, I suddenly had a playground that wasn't rendering. I quit and restarted Xcode without joy. I then turned off assistant editor and turned it back on and the UI appeared. Bottom line, the `liveView` is a bit flaky in Xcode 8.2.1. – Rob Feb 25 '17 at 18:31

3 Answers3

4

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

Ocunidee
  • 1,769
  • 18
  • 20
  • Is the expected result that the playground opens the actual Simulator App? Cause I can see the "Launching simulator" status, then "Running [PlayrgroundName]" but the assistant editor is blank and the Simulator doesn't open. Also I don't even have iOS9 devices in the sim, just 10.2 and tvOS. – konrad Mar 21 '17 at 14:29
  • I switched to tvOS and back to iOS 10 just to stir things - still not working but it's good to hear there are some issues. I'll try to fiddle and see if any other voodoo helps. – konrad Mar 21 '17 at 14:32
  • yes, the simulator is supposed to open if it is not already open. You can check your dock for that. I'm making it run on iPhone SE, I've tried iPads and it's not working for me – Ocunidee Mar 21 '17 at 15:11
2

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?

Eddev
  • 890
  • 1
  • 10
  • 21
  • I can see the assistant editor right pane but' it's just black. I can see the partial results when I click on the icons next to intermediate results in the mid screen pane (eye or small rect). Here's screnshot: http://imgur.com/a/DwVbB – konrad Mar 15 '17 at 10:59
0

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 ?

Acrasia
  • 201
  • 1
  • 8
  • Do you get the side result in the assistant aditor pane? – konrad Feb 20 '17 at 16:25
  • Yes, just like you and just like the link I mentioned. Really, I don't understand what do you expect. – Acrasia Feb 20 '17 at 16:26
  • I expect to get same thing as you but I don't. My assistant editor is empty. The only way to see anything for me is to click one of the small preview buttons which show up when I hover a line in the grey printed results pane (the mid left one in your screenshot). The results show only as a temporary popup or a scaled down preview between the lines of left side editor. I would like to see the end result of running the playground code. – konrad Feb 20 '17 at 16:32
  • In the 'duplicate quesion' Duncan C has similar problems but his XCode crashed. Mine just fails silently. – konrad Feb 20 '17 at 16:33
  • And my partial solution works for the example above but not for one like this: https://gist.github.com/koko236/27a8f9a2bcf0355b07072246bd5a4710 – konrad Feb 20 '17 at 16:42