title: uncaught exception 'NSInvalidArgumentException', reason: '-[UITableViewSection view]: unrecognized selector sent to instance 0x600003721110'
body: <p>The error occurs when I go into my settings view controller. Settings has a UISegmentedControl which is connected to theme.swift through SettingsViewcontroller.swift ViewDidLoad().</p>
  
  <p>I've been following a tutorial, but got an error about the Theme enum which went away when I added the Int value type to the enum declaration. Theme is returned by the ThemeManager struct with a rawValue.</p>
  
  <p>I'm pretty sure the error is being caused by settingsViewController.swift. Since the only code that is executed when the settingsViewController.swift is loaded is in the viewDidLoad() method, I'm thinking the problem lies there.</p>
  
  <p>The reason for the uncaught exception is 'UITableViewSection view', which I'm guessing is the UISegmentControl, as the only other section is an apply button, whose code isn't run until it's pressed?!</p>
  
  <p>I've been reading about similar errors, and have gathered that a method is being called on an object that doesn't contain said method. I don't see anything like that, but I'm not sure about line 30 in Theme.swift. I had to change the tutorial code because of multiple errors. Either that or the Theme enum shouldn't be an Int (line 13 Theme.swift).</p>
  
  <pre><code>Theme.swift
  
  import UIKit
  
  let SelectedThemeKey = "SelectedTheme"
  
  enum Theme : Int {
      case Default, Dark, Graphical
  
      var mainColor: UIColor {
          switch self {
          case .Default:
              return UIColor(red: 87.0/255.0, green: 188.0/255.0, blue: 95.0/255.0, alpha: 1.0)
          case .Dark:
              return UIColor(red: 242.0/255.0, green: 101.0/255.0, blue: 34.0/255.0, alpha: 1.0)
          case .Graphical:
              return UIColor(red: 10.0/255.0, green: 10.0/255.0, blue: 10.0/255.0, alpha: 1.0)
          }
      }
  }
  
  struct ThemeManager {
      static func currentTheme() -&gt; Theme {
          if let storedTheme = (UserDefaults.standard.value(forKey: SelectedThemeKey) as AnyObject).integerValue {
              return Theme(rawValue: storedTheme)!
          } else {
              return .Default
          }
      }
  
      static func applyTheme(theme: Theme) {
          // 1
          UserDefaults.standard.setValue(theme.rawValue, forKey: SelectedThemeKey)
          UserDefaults.standard.synchronize()
  
          // 2
          let sharedApplication = UIApplication.shared
          sharedApplication.delegate?.window??.tintColor = theme.mainColor
      }
  }
  
  SettingsViewcontroller.swift
  
  import UIKit
  
  class SettingsViewController: UITableViewController {
  
      @IBOutlet weak var themeSelector: UISegmentedControl!
      @IBOutlet weak var applyButton: UIButton!
  
      //@IBOutlet weak var settingsTableView: UITableView!
  
      //let settingsTableOptions = ["Turn On Dark Mode"]
  
      override func viewDidLoad() {
          super.viewDidLoad()
  
          // Register custom cell
          //let nib = UINib(nibName: "settingsTableCell", bundle: nil)
          //settingsTableView.register(nib, forCellReuseIdentifier: "Settings")
  
          themeSelector.selectedSegmentIndex = ThemeManager.currentTheme().rawValue
      }
  
      func dismiss() {
          self.dismiss(animated: true, completion: nil)
      }
  
      @IBAction func applyTheme(sender: UIButton) {
          if let selectedTheme = Theme(rawValue: themeSelector.selectedSegmentIndex) {
              ThemeManager.applyTheme(theme: selectedTheme)
          }
          dismiss()
      }
  
      override func viewWillAppear(_ animated: Bool) {
          super.viewWillAppear(animated);
      }
  }
  
  
  
  I've setup the story board for the settings view exactly as the tutorial, and don't recognise any options that could cause my problem.
  </code></pre>