     }
     
     func touchIDSwitchAction(uiSwitch: UISwitch) {
-        if uiSwitch.isOn {
-            Defaults[.isTouchIDOn] = true
-            Globals.passcodeConfiguration.isTouchIDAllowed = true
+        if !Globals.passcodeConfiguration.isTouchIDAllowed {
+            // switch off
+            uiSwitch.isOn = Defaults[.isTouchIDOn]  // false
+            Utils.alert(title: "Notice", message: "Please set the passcode lock first.", controller: self, completion: nil)
         } else {
-            Defaults[.isTouchIDOn] = false
-            Globals.passcodeConfiguration.isTouchIDAllowed = false
+            Defaults[.isTouchIDOn] = uiSwitch.isOn
         }
         let appDelegate = UIApplication.shared.delegate as! AppDelegate
         appDelegate.passcodeLockPresenter = PasscodeLockPresenter(mainWindow: appDelegate.window, configuration: Globals.passcodeConfiguration)

        touchIDTableViewCell.accessoryView = touchIDSwitch
        setPGPKeyTableViewCellDetailText()
        setPasswordRepositoryTableViewCellDetailText()
        setTouchIDSwitch()
        setPasscodeLockRepositoryTableViewCellDetailText()
    }
    
    private func setPasscodeLockRepositoryTableViewCellDetailText() {
        if PasscodeLockRepository().hasPasscode {
            self.passcodeTableViewCell.detailTextLabel?.text = "On"
        } else {
            self.passcodeTableViewCell.detailTextLabel?.text = "Off"
            touchIDSwitch.isEnabled = false
            Globals.passcodeConfiguration.isTouchIDAllowed = false
        }
    }
    

        }
    }
    
    func actOnPasswordStoreErasedNotification() {
        setPGPKeyTableViewCellDetailText()
        setPasswordRepositoryTableViewCellDetailText()
        setPasscodeLockTouchIDCells()

        let appDelegate = UIApplication.shared.delegate as! AppDelegate
        appDelegate.passcodeLockPresenter = PasscodeLockPresenter(mainWindow: appDelegate.window, configuration: Globals.passcodeConfiguration)
