title: How to make an Xcode playground rotate to landscape
body: <p>I am trying to test a landscape view, but so far I cannot make progress. My code looks like this:</p>
  
  <pre><code>import UIKit
  import PlaygroundSupport
  
  class MyViewController : UIViewController {
  
    override func loadView() {
  
      let view = UIView()
      view.backgroundColor = .white
      let label = UILabel()
      label.text = "Hallo"
      label.translatesAutoresizingMaskIntoConstraints = false
      view.addSubview(label)
      self.view = view
      NSLayoutConstraint.activate([label.topAnchor.constraint(equalTo: view.topAnchor, constant: 20),
                                   label.centerXAnchor.constraint(equalTo: view.centerXAnchor)])
      simulateDeviceRotation(toOrientation: .landscapeLeft)
   }
  
    override func viewDidAppear(_ animated: Bool) {
  
      //simulateDeviceRotation(toOrientation: .landscapeLeft)
  
    }
  }
  // Present the view controller in the Live View window
  func simulateDeviceRotation(toOrientation orientation: UIDeviceOrientation) {
    let orientationValue = NSNumber(value: orientation.rawValue)
    UIDevice.current.setValue(orientationValue, forKey: "orientation")
  }
  
  PlaygroundPage.current.liveView = MyViewController()
  </code></pre>
  
  <p>When I uncomment the call to <code>simulateDeviceRotation(toOrientation:)</code> in <code>loadView()</code>, the result is:</p>
  
  <p><a href="https://i.stack.imgur.com/p1F7Y.png" rel="nofollow noreferrer">Rotation in loadView()</a></p>
  
  <p>And, when I uncomment <code>simulateDeviceRotation(toOrientation:)</code> in <code>viewDidAppear(_:)</code>, the result is:</p>
  
  <p><a href="https://i.stack.imgur.com/43dSw.png" rel="nofollow noreferrer">rotation in viewDidAppear(_:)</a></p>
  
  <p>Of course, I would like to see the second result, but with the horizontal rotation of the first. Can you please point me in the right direction? I am missing something but I have not been able to finde it.</p>