<commit_before>import UIKit
import TroposCore

private enum SegueIdentifier: String {
    case privacyPolicy = "ShowWebViewController"
    case acknowledgements = "ShowTextViewController"

    init?(identifier: String?) {
        guard let identifier = identifier else { return nil }
        self.init(rawValue: identifier)
    }
}

enum Section: Int {
    case unitSystem
    case info
    case about
}

enum UnitSystemSection: Int {
    case metric
    case imperial
}

enum InfoSection: Int {
    case privacyPolicy
    case acknowledgements
    case forecast
}

enum AboutSection: Int {
    case thoughtbot
}

class SettingsTableViewController: UITableViewController {
    @IBOutlet var thoughtbotImageView: UIImageView!
    private let settingsController = SettingsController()

    override func viewDidLoad() {
        super.viewDidLoad()

        settingsController.unitSystemChanged = { [weak self] unitSystem in
          guard let indexPath = self?.indexPathForUnitSystem(unitSystem) else { return }
          self?.tableView.checkCellAtIndexPath(indexPath)
        }

        thoughtbotImageView.tintColor = .lightText
        thoughtbotImageView.image = thoughtbotImageView.image?.withRenderingMode(
          .alwaysTemplate
        )

        NotificationCenter.default.addObserver(
          forName: .UIApplicationWillResignActive,
          object: nil,
          queue: nil
        ) { [weak self] _ in
          guard let selectedIndexPath = self?.tableView.indexPathForSelectedRow else { return }
          self?.tableView.deselectRow(at: selectedIndexPath, animated: true)
        }
    }

    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        tableView.checkCellAtIndexPath(indexPathForUnitSystem(settingsController.unitSystem))
    }

    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        switch SegueIdentifier(identifier: segue.identifier) {
        case .privacyPolicy?:
            let webViewController = segue.destination as? WebViewController
            webViewController?.url = URL(string: "http://www.troposweather.com/privacy/")!
        case .acknowledgements?:
            let textViewController = segue.destination as? TextViewController
            let fileURL = Bundle.main.url(
              forResource: "Pods-Tropos-settings-metadata",
              withExtension: "plist"
            )
            let parser = fileURL.flatMap { AcknowledgementsParser(fileURL: $0) }
            textViewController?.text = parser?.displayString()
        case nil:
            break
        }
    }

    override func tableView(
      _ tableView: UITableView,
      didSelectRowAt
      indexPath: IndexPath<commit_msg>Resolve warning for forgetting to remove observation<commit_after>import UIKit
import TroposCore

private enum SegueIdentifier: String {
    case privacyPolicy = "ShowWebViewController"
    case acknowledgements = "ShowTextViewController"

    init?(identifier: String?) {
        guard let identifier = identifier else { return nil }
        self.init(rawValue: identifier)
    }
}

enum Section: Int {
    case unitSystem
    case info
    case about
}

enum UnitSystemSection: Int {
    case metric
    case imperial
}

enum InfoSection: Int {
    case privacyPolicy
    case acknowledgements
    case forecast
}

enum AboutSection: Int {
    case thoughtbot
}

class SettingsTableViewController: UITableViewController {
    @IBOutlet var thoughtbotImageView: UIImageView!
    private var resignActiveObservation: Any?
    private let settingsController = SettingsController()

    override func viewDidLoad() {
        super.viewDidLoad()

        settingsController.unitSystemChanged = { [weak self] unitSystem in
          guard let indexPath = self?.indexPathForUnitSystem(unitSystem) else { return }
          self?.tableView.checkCellAtIndexPath(indexPath)
        }

        thoughtbotImageView.tintColor = .lightText
        thoughtbotImageView.image = thoughtbotImageView.image?.withRenderingMode(
          .alwaysTemplate
        )

        resignActiveObservation = NotificationCenter.default.addObserver(
          forName: .UIApplicationWillResignActive,
          object: nil,
          queue: nil
        ) { [weak self] _ in
          guard let selectedIndexPath = self?.tableView.indexPathForSelectedRow else { return }
          self?.tableView.deselectRow(at: selectedIndexPath, animated: true)
        }
    }

    deinit {
        if let resignActiveObservation = resignActiveObservation {
            NotificationCenter.default.removeObserver(resignActiveObservation)
        }
    }

    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        tableView.checkCellAtIndexPath(indexPathForUnitSystem(settingsController.unitSystem))
    }

    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        switch SegueIdentifier(identifier: segue.identifier) {
        case .privacyPolicy?:
            let webViewController = segue.destination as? WebViewController
            webViewController?.url = URL(string: "http://www.troposweather.com/privacy/")!
        case .acknowledgements?:
            let textViewController = segue.destination as? TextViewController
            let fileURL = Bundle.main.url(
              forResource: "Pods-Tropos-settings-metadata",
              withExtension: "plist"
            )
            let parser = fileURL.flatMap { AcknowledgementsParser(fileURL: $0) }
            textViewController?.text = parser?.displayString()
        case nil:
            break
        }
    }

    override func tableView(
      _ tableView: UITableView,
      didSelectRowAt
      indexPath: IndexPath
{'fraction_non_alphanumeric': 0.07231441048034934, 'fraction_numerical': 0.00034934497816593884, 'mean_word_length': 2.7596848325673013, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3435444', 'n_tokens_mistral': 1511, 'n_tokens_neox': 1433, 'n_words': 348}