title: Python error while coding in Swift: unexpected indent (Xcode 11)
body: <p>Edit:
  For those who want actual code, please consult this link for all related source code.
  <a href="https://github.com/objcio/S01E118-introduction-prototype" rel="nofollow noreferrer">https://github.com/objcio/S01E118-introduction-prototype</a></p>
  
  <p>Why am I getting the following error:</p>
  
  <blockquote>
    <p>error: module importing failed: unexpected indent
    (sniff_objc_exception_throw.py, line 7)   File "temp.py", line 1, in
    </p>
  </blockquote>
  
  <p>I am using a project example from SwiftTalk which doesn't have any obvious python code anywhere, which makes me think this might be an Xcode import issue.  Has anyone seen this? Is there something I can do to solve the issue?</p>
  
  <p><a href="https://i.stack.imgur.com/teGA3.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/teGA3.jpg" alt="enter image description here"></a></p>
  
  <p>The project code uses an older version of Swift (which matt points out below...).  Here is my code after updating to remove all compile errors and running the Convert/Update to Swift 5 Utility:</p>
  
  <pre><code>import UIKit
  
  extension UIView {
      func setSubviews&lt;S: Sequence&gt;(_ other: S) where S.Element == UIView {
          let views = Set(other)
          let sub = Set(subviews)
          for v in sub.subtracting(views) {
              v.removeFromSuperview()
          }
          for v in views.subtracting(sub) {
              addSubview(v)
          }
      }
  }
  
  
  extension UILabel {
      convenience init(text: String, size: UIFont.TextStyle, multiline: Bool = false) {
          self.init()
          font = UIFont.preferredFont(forTextStyle: size)
          self.text = text
          adjustsFontForContentSizeCategory = true
          if multiline {
              numberOfLines = 0
          }
      }
  }
  
  indirect enum Layout {
      case view(UIView, Layout)
      case newline(Layout)
      case choice(Layout, Layout)
      case empty
  }
  
  extension Layout {
      func apply(containerWidth: CGFloat) -&gt; [UIView] {
          var result: [UIView] = []
          var origin: CGPoint = .zero
          var current: Layout = self
          var lineHeight: CGFloat = 0
          while true {
          switch current {
              case let .view(v, rest):
                  result.append(v)
                  let availableWidth = containerWidth - origin.x
                  let size = v.sizeThatFits(CGSize(width: availableWidth, height: .greatestFiniteMagnitude))
                  v.frame = CGRect(origin: origin, size: size)
                  lineHeight = max(lineHeight, size.height)
                  origin.x += size.width
                  current = rest
              case let .newline(rest):
                  origin.x = 0
                  origin.y += lineHeight
                  lineHeight = 0
                  current = rest
              case let .choice(first, second):
                  if first.fits(currentX: origin.x, containerWidth: containerWidth) {
                      current = first
                  } else {
                      current = second
                  }
              case .empty:
                  return result
              }
          }
      }
  
      func fits(currentX: CGFloat, containerWidth: CGFloat) -&gt; Bool {
          var x = currentX
          var current: Layout = self
          while true {
              switch current {
              case let .view(v, rest):
                  let availableWidth = containerWidth - x
                  let size = v.sizeThatFits(CGSize(width: availableWidth, height: .greatestFiniteMagnitude))
                  x += size.width
                  if x &gt;= containerWidth { return false }
                  current = rest
              case let .newline(rest):
                  x = 0
                  current = rest
              case let .choice(first, second):
                  if first.fits(currentX: x, containerWidth: containerWidth) {
                      return true
                  } else {
                      current = second
                  }
              case .empty:
                  return true
              }
          }
      }
  }
  
  final class LayoutContainer: UIView {
      let layout: Layout
      init(_ layout: Layout) {
          self.layout = layout
          super.init(frame: .zero)
  
  //        NotificationCenter.default.addObserver(self, selector: #selector(setNeedsLayout), name: Notification.Name.UIContentSizeCategory.didChangeNotification, object: nil)
      }
  
      required init?(coder aDecoder: NSCoder) {
          fatalError("init(coder:) has not been implemented")
      }
  
      override func layoutSubviews() {
          let views = layout.apply(containerWidth: bounds.width)
          setSubviews(views)
      }
  }
  
  class ViewController: UIViewController {
      override func viewDidLoad() {
          super.viewDidLoad()
  
          let titleLabel = UILabel(text: "Building a Layout Library", size: .headline, multiline: true)
          let episodeNumber = UILabel(text: "Episode 123", size: .body)
          let episodeDate = UILabel(text: "September 23", size: .body)
  
          let horizontal = Layout.view(episodeNumber, Layout.view(episodeDate, .empty))
          let vertical = Layout.view(episodeNumber, .newline(Layout.view(episodeDate, .empty)))
          let layout = Layout.view(titleLabel, .newline(
              .choice(horizontal, vertical)
              ))
  
          let container = LayoutContainer(layout)
          container.translatesAutoresizingMaskIntoConstraints = false
  
          view.addSubview(container)
          view.addConstraints([
              container.topAnchor.constraint(equalTo: view.layoutMarginsGuide.topAnchor),
              container.leadingAnchor.constraint(equalTo: view.layoutMarginsGuide.leadingAnchor),
              container.trailingAnchor.constraint(equalTo: view.layoutMarginsGuide.trailingAnchor),
          ])
  
      }
  }
  </code></pre>
  
  <p>To be clear: if you copy and paste this code over the project's existing ViewController.swift content, the project compiles, then runs with only the indicated error (module importing failed:....)</p>