Problems with Swift Playgrounds on iPad

Hi,


Everytime I try to add 3 subviews Swift Playgrounds says There was a problem encountered while running this Playground.


PLEASE HELP

Replies

When asking for technical help, you need to provide enough information for someone to help you. My recommendation is that you reduce your program to the smallest example that reproduces the issue, and then post relevant code snippets here. You should also include information about the environment in which you’re seeing the problem.

For example, to test this out I used Swift Playgrounds on my iPad to create a new playground from the Blank starting point, and then entered the code shown below:

import UIKit
import PlaygroundSupport

class MyViewController : UIViewController {
    override func loadView() {
        let view = UIView()
        view.backgroundColor = .white

        for (i, color) in [UIColor.red, .green, .blue, .cyan, .magenta, .yellow].enumerated() {
            let viewFrame = CGRect(x: 100.0, y: 200.0 + Double(i) * 20.0, width: 200.0, height: 20.0)
            let v = UIView(frame: viewFrame)
            v.backgroundColor = color
            view.addSubview(v)
        }
        self.view = view
    }
}
PlaygroundPage.current.liveView = MyViewController()

The live view shows 6 coloured bars, just as I expected.

This was using Swift Playgrounds 2.2 on iOS 12.1.4.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"