From 6f29497ec89daedebecf76bb6569e06e66143257 Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Wed, 23 Oct 2019 22:27:08 -0700 Subject: [PATCH] Move NSTextFieldDelegate conformance to separate extension. Handle the optional nil case in controlTextDidChange. --- .../AddFolder/AddFolderWindowController.swift | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/Mac/MainWindow/AddFolder/AddFolderWindowController.swift b/Mac/MainWindow/AddFolder/AddFolderWindowController.swift index 5cec5174e..2a0153582 100644 --- a/Mac/MainWindow/AddFolder/AddFolderWindowController.swift +++ b/Mac/MainWindow/AddFolder/AddFolderWindowController.swift @@ -10,7 +10,7 @@ import AppKit import Articles import Account -class AddFolderWindowController : NSWindowController, NSTextFieldDelegate { +class AddFolderWindowController : NSWindowController { @IBOutlet var folderNameTextField: NSTextField! @IBOutlet var accountPopupButton: NSPopUpButton! @@ -79,20 +79,23 @@ class AddFolderWindowController : NSWindowController, NSTextFieldDelegate { // MARK: Actions @IBAction func cancel(_ sender: Any?) { - hostWindow!.endSheet(window!, returnCode: NSApplication.ModalResponse.cancel) } @IBAction func addFolder(_ sender: Any?) { - hostWindow!.endSheet(window!, returnCode: NSApplication.ModalResponse.OK) } +} - // MARK: Text Field Delegate +// MARK: Text Field Delegate + +extension AddFolderWindowController: NSTextFieldDelegate { func controlTextDidChange(_ obj: Notification) { - if let value = (obj.object as? NSTextField)?.stringValue { - addFolderButton.isEnabled = !value.isEmpty + guard let folderName = (obj.object as? NSTextField)?.stringValue else { + addFolderButton.isEnabled = false + return } + addFolderButton.isEnabled = !folderName.isEmpty } }