From 2d50a4037066751caeebd377f4f9667d87ff3e90 Mon Sep 17 00:00:00 2001 From: Bob Sun Date: Thu, 2 Mar 2017 16:51:46 +0800 Subject: [PATCH] Use lazy var for touchIDSwitch to simplify code --- pass/Controllers/SettingsTableViewController.swift | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/pass/Controllers/SettingsTableViewController.swift b/pass/Controllers/SettingsTableViewController.swift index 74bb952..45c4f95 100644 --- a/pass/Controllers/SettingsTableViewController.swift +++ b/pass/Controllers/SettingsTableViewController.swift @@ -14,7 +14,12 @@ import PasscodeLock class SettingsTableViewController: UITableViewController { - let touchIDSwitch = UISwitch(frame: CGRect.zero) + lazy var touchIDSwitch: UISwitch = { + let uiSwitch = UISwitch(frame: CGRect.zero) + uiSwitch.onTintColor = Globals.blue + uiSwitch.addTarget(self, action: #selector(touchIDSwitchAction), for: UIControlEvents.valueChanged) + return uiSwitch + }() @IBOutlet weak var pgpKeyTableViewCell: UITableViewCell! @IBOutlet weak var touchIDTableViewCell: UITableViewCell! @@ -170,9 +175,7 @@ class SettingsTableViewController: UITableViewController { super.viewDidLoad() NotificationCenter.default.addObserver(self, selector: #selector(SettingsTableViewController.actOnPasswordStoreErasedNotification), name: NSNotification.Name(rawValue: "passwordStoreErased"), object: nil) self.passwordRepositoryTableViewCell.detailTextLabel?.text = Defaults[.gitRepositoryURL]?.host - touchIDSwitch.onTintColor = UIColor(displayP3Red: 0, green: 122.0/255, blue: 1, alpha: 1) touchIDTableViewCell.accessoryView = touchIDSwitch - touchIDSwitch.addTarget(self, action: #selector(touchIDSwitchAction), for: UIControlEvents.valueChanged) setPGPKeyTableViewCellDetailText() setPasswordRepositoryTableViewCellDetailText() setTouchIDSwitch()