From 9e5ced8055ebdcfb69a6e09d8c1f4f93e8a42900 Mon Sep 17 00:00:00 2001 From: ShikiSuen Date: Mon, 11 Apr 2022 16:01:53 +0800 Subject: [PATCH] Xcode // AppCode quality check (Swift). --- Installer/AppDelegate.swift | 6 ++-- Installer/ArchiveUtil.swift | 2 +- .../Sources/OpenCC/ConversionDictionary.swift | 4 +-- .../Sources/OpenCC/DictionaryLoader.swift | 18 ++++++------ .../Sources/OpenCC/WeakValueCache.swift | 2 +- .../Tests/OpenCCTests/OpenCCTests.swift | 2 +- .../SindreSorhus/Preferences/Container.swift | 2 +- .../SindreSorhus/Preferences/Pane.swift | 8 +++--- .../SindreSorhus/Preferences/Section.swift | 2 ++ Source/3rdParty/VDKComboBox/VDKComboBox.swift | 2 +- Source/Modules/AppDelegate.swift | 20 ++++++------- .../AppleKeyboardConverter.swift | 8 +++--- .../ControllerModules/InputState.swift | 4 +-- .../Modules/ControllerModules/KeyParser.swift | 4 +-- .../vChewingKanjiConverter.swift | 2 +- .../FileHandlers/FSEventStreamHelper.swift | 2 +- Source/Modules/IMEModules/IME.swift | 10 ++++--- .../Modules/IMEModules/ctlInputMethod.swift | 2 +- Source/Modules/IMEModules/mgrPrefs.swift | 10 +++---- .../LangModelRelated/mgrLangModel.swift | 28 +++++++++---------- Source/Modules/SFX/clsSFX.swift | 2 +- .../CandidateUI/ctlCandidateHorizontal.swift | 12 ++++---- .../UI/CandidateUI/ctlCandidateVertical.swift | 12 ++++---- Source/UI/NotifierUI/NotifierController.swift | 18 ++++++------ Source/WindowControllers/ctlPrefWindow.swift | 4 +-- UserPhraseEditor/AppDelegate.swift | 2 +- UserPhraseEditor/Content.swift | 2 +- UserPhraseEditor/Document.swift | 6 ++-- UserPhraseEditor/StringExtension.swift | 2 +- 29 files changed, 101 insertions(+), 97 deletions(-) diff --git a/Installer/AppDelegate.swift b/Installer/AppDelegate.swift index 2298efc1..18399314 100644 --- a/Installer/AppDelegate.swift +++ b/Installer/AppDelegate.swift @@ -78,7 +78,7 @@ class AppDelegate: NSWindowController, NSApplicationDelegate { return } self.installingVersion = installingVersion - self.archiveUtil = ArchiveUtil(appName: kTargetBin, targetAppBundleName: kTargetBundle) + archiveUtil = ArchiveUtil(appName: kTargetBin, targetAppBundleName: kTargetBundle) _ = archiveUtil?.validateIfNotarizedArchiveExists() cancelButton.nextKeyView = installButton @@ -153,7 +153,7 @@ class AppDelegate: NSWindowController, NSApplicationDelegate { atPath: (kTargetPartialPath as NSString).expandingTildeInPath) == false { - self.installInputMethod( + installInputMethod( previousExists: false, previousVersionNotFullyDeactivatedWarning: false) return } @@ -208,7 +208,7 @@ class AppDelegate: NSWindowController, NSApplicationDelegate { timeInterval: kTranslocationRemovalTickInterval, target: self, selector: #selector(timerTick(_:)), userInfo: nil, repeats: true) } else { - self.installInputMethod( + installInputMethod( previousExists: false, previousVersionNotFullyDeactivatedWarning: false) } } diff --git a/Installer/ArchiveUtil.swift b/Installer/ArchiveUtil.swift index 737fd959..85e0eebb 100644 --- a/Installer/ArchiveUtil.swift +++ b/Installer/ArchiveUtil.swift @@ -83,7 +83,7 @@ struct ArchiveUtil { } func unzipNotarizedArchive() -> String? { - if !self.validateIfNotarizedArchiveExists() { + if !validateIfNotarizedArchiveExists() { return nil } guard let notarizedArchive = notarizedArchive, diff --git a/Packages/SwiftyOpenCC/Sources/OpenCC/ConversionDictionary.swift b/Packages/SwiftyOpenCC/Sources/OpenCC/ConversionDictionary.swift index df7755ff..824a744c 100644 --- a/Packages/SwiftyOpenCC/Sources/OpenCC/ConversionDictionary.swift +++ b/Packages/SwiftyOpenCC/Sources/OpenCC/ConversionDictionary.swift @@ -18,13 +18,13 @@ class ConversionDictionary { guard let dict = CCDictCreateMarisaWithPath(path) else { throw ConversionError(ccErrorno) } - self.group = [] + group = [] self.dict = dict } init(group: [ConversionDictionary]) { var rawGroup = group.map { $0.dict } self.group = group - self.dict = CCDictCreateWithGroup(&rawGroup, rawGroup.count) + dict = CCDictCreateWithGroup(&rawGroup, rawGroup.count) } } diff --git a/Packages/SwiftyOpenCC/Sources/OpenCC/DictionaryLoader.swift b/Packages/SwiftyOpenCC/Sources/OpenCC/DictionaryLoader.swift index 83dcc9db..ca7a2a76 100644 --- a/Packages/SwiftyOpenCC/Sources/OpenCC/DictionaryLoader.swift +++ b/Packages/SwiftyOpenCC/Sources/OpenCC/DictionaryLoader.swift @@ -30,7 +30,7 @@ extension ChineseConverter { throw ConversionError.fileNotFound } return try DictionaryLoader.dictCache.value(for: path) { - return try ConversionDictionary(path: path) + try ConversionDictionary(path: path) } } } @@ -44,15 +44,15 @@ extension ChineseConverter.DictionaryLoader { } func conversionChain(options: ChineseConverter.Options) throws -> [ConversionDictionary] { - return try options.conversionChain.compactMap { names in + try options.conversionChain.compactMap { names in switch names.count { - case 0: - return nil - case 1: - return try dict(names.first!) - case _: - let dicts = try names.map(dict) - return ConversionDictionary(group: dicts) + case 0: + return nil + case 1: + return try dict(names.first!) + case _: + let dicts = try names.map(dict) + return ConversionDictionary(group: dicts) } } } diff --git a/Packages/SwiftyOpenCC/Sources/OpenCC/WeakValueCache.swift b/Packages/SwiftyOpenCC/Sources/OpenCC/WeakValueCache.swift index d945a371..59a5a78c 100644 --- a/Packages/SwiftyOpenCC/Sources/OpenCC/WeakValueCache.swift +++ b/Packages/SwiftyOpenCC/Sources/OpenCC/WeakValueCache.swift @@ -23,7 +23,7 @@ class WeakValueCache { private var lock = NSLock() func value(for key: Key) -> Value? { - return storage[key]?.value + storage[key]?.value } func value(for key: Key, make: () throws -> Value) rethrows -> Value { diff --git a/Packages/SwiftyOpenCC/Tests/OpenCCTests/OpenCCTests.swift b/Packages/SwiftyOpenCC/Tests/OpenCCTests/OpenCCTests.swift index 12dd45dd..52b8276d 100644 --- a/Packages/SwiftyOpenCC/Tests/OpenCCTests/OpenCCTests.swift +++ b/Packages/SwiftyOpenCC/Tests/OpenCCTests/OpenCCTests.swift @@ -16,7 +16,7 @@ let testCases: [(String, ChineseConverter.Options)] = [ class OpenCCTests: XCTestCase { func converter(option: ChineseConverter.Options) throws -> ChineseConverter { - return try ChineseConverter(options: option) + try ChineseConverter(options: option) } func testConversion() throws { diff --git a/Source/3rdParty/SindreSorhus/Preferences/Container.swift b/Source/3rdParty/SindreSorhus/Preferences/Container.swift index 7ccba756..d9ba172b 100755 --- a/Source/3rdParty/SindreSorhus/Preferences/Container.swift +++ b/Source/3rdParty/SindreSorhus/Preferences/Container.swift @@ -56,7 +56,7 @@ extension Preferences { minimumLabelWidth: Double = 0, @SectionBuilder builder: @escaping () -> [Section] ) { - self.sectionBuilder = builder + sectionBuilder = builder self.contentWidth = contentWidth self.minimumLabelWidth = minimumLabelWidth } diff --git a/Source/3rdParty/SindreSorhus/Preferences/Pane.swift b/Source/3rdParty/SindreSorhus/Preferences/Pane.swift index 31f5e391..beb4f518 100755 --- a/Source/3rdParty/SindreSorhus/Preferences/Pane.swift +++ b/Source/3rdParty/SindreSorhus/Preferences/Pane.swift @@ -52,7 +52,7 @@ extension Preferences { self.identifier = identifier self.title = title self.toolbarIcon = toolbarIcon - self.content = contentView() + content = contentView() } public var body: some View { content } @@ -76,9 +76,9 @@ extension Preferences { toolbarIcon: NSImage, content: Content ) { - self.preferencePaneIdentifier = identifier - self.preferencePaneTitle = title - self.toolbarItemIcon = toolbarIcon + preferencePaneIdentifier = identifier + preferencePaneTitle = title + toolbarItemIcon = toolbarIcon super.init(rootView: content) } diff --git a/Source/3rdParty/SindreSorhus/Preferences/Section.swift b/Source/3rdParty/SindreSorhus/Preferences/Section.swift index 15ad0400..6ca000c8 100755 --- a/Source/3rdParty/SindreSorhus/Preferences/Section.swift +++ b/Source/3rdParty/SindreSorhus/Preferences/Section.swift @@ -78,6 +78,7 @@ extension Preferences { - Parameters: - bottomDivider: Whether to place a `Divider` after the section content. Default is `false`. - verticalAlignement: The vertical alignment of the section content. + - verticalAlignment: - label: A view describing preference handled by this section. - content: A content view. */ @@ -103,6 +104,7 @@ extension Preferences { - title: A string describing preference handled by this section. - bottomDivider: Whether to place a `Divider` after the section content. Default is `false`. - verticalAlignement: The vertical alignment of the section content. + - verticalAlignment: - content: A content view. */ public init( diff --git a/Source/3rdParty/VDKComboBox/VDKComboBox.swift b/Source/3rdParty/VDKComboBox/VDKComboBox.swift index 2c14bc58..7f7ae3a0 100644 --- a/Source/3rdParty/VDKComboBox/VDKComboBox.swift +++ b/Source/3rdParty/VDKComboBox/VDKComboBox.swift @@ -18,7 +18,7 @@ struct ComboBox: NSViewRepresentable { @Binding var text: String func makeCoordinator() -> Coordinator { - return Coordinator(self) + Coordinator(self) } func makeNSView(context: Context) -> NSComboBox { diff --git a/Source/Modules/AppDelegate.swift b/Source/Modules/AppDelegate.swift index 2de9b799..724b3806 100644 --- a/Source/Modules/AppDelegate.swift +++ b/Source/Modules/AppDelegate.swift @@ -127,13 +127,13 @@ class AppDelegate: NSObject, NSApplicationDelegate, ctlNonModalAlertWindowDelega checkTask = VersionUpdateApi.check(forced: forced) { [self] result in defer { - self.checkTask = nil + checkTask = nil } switch result { case .success(let apiResult): switch apiResult { case .shouldUpdate(let report): - self.updateNextStepURL = report.siteUrl + updateNextStepURL = report.siteUrl let content = String( format: NSLocalizedString( "You're currently using vChewing %@ (%@), a new version %@ (%@) is now available. Do you want to visit vChewing's website to download the version?%@", @@ -144,7 +144,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, ctlNonModalAlertWindowDelega report.remoteVersion, report.versionDescription) IME.prtDebugIntel("vChewingDebug: \(content)") - self.currentAlertType = "Update" + currentAlertType = "Update" ctlNonModalAlertWindow.shared.show( title: NSLocalizedString( "New Version Available", comment: ""), @@ -170,7 +170,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, ctlNonModalAlertWindowDelega comment: ""), message) let buttonTitle = NSLocalizedString("Dismiss", comment: "") IME.prtDebugIntel("vChewingDebug: \(content)") - self.currentAlertType = "Update" + currentAlertType = "Update" ctlNonModalAlertWindow.shared.show( title: title, content: content, confirmButtonTitle: buttonTitle, @@ -185,7 +185,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, ctlNonModalAlertWindowDelega } func selfUninstall() { - self.currentAlertType = "Uninstall" + currentAlertType = "Uninstall" let content = String( format: NSLocalizedString( "This will remove vChewing Input Method from this user account, requiring your confirmation.", @@ -199,25 +199,25 @@ class AppDelegate: NSObject, NSApplicationDelegate, ctlNonModalAlertWindowDelega } func ctlNonModalAlertWindowDidConfirm(_ controller: ctlNonModalAlertWindow) { - switch self.currentAlertType { + switch currentAlertType { case "Uninstall": NSWorkspace.shared.openFile( mgrLangModel.dataFolderPath(isDefaultFolder: true), withApplication: "Finder") IME.uninstall(isSudo: false, selfKill: true) case "Update": - if let updateNextStepURL = self.updateNextStepURL { + if let updateNextStepURL = updateNextStepURL { NSWorkspace.shared.open(updateNextStepURL) } - self.updateNextStepURL = nil + updateNextStepURL = nil default: break } } func ctlNonModalAlertWindowDidCancel(_ controller: ctlNonModalAlertWindow) { - switch self.currentAlertType { + switch currentAlertType { case "Update": - self.updateNextStepURL = nil + updateNextStepURL = nil default: break } diff --git a/Source/Modules/ControllerModules/AppleKeyboardConverter.swift b/Source/Modules/ControllerModules/AppleKeyboardConverter.swift index 7d8131b8..887b2c24 100644 --- a/Source/Modules/ControllerModules/AppleKeyboardConverter.swift +++ b/Source/Modules/ControllerModules/AppleKeyboardConverter.swift @@ -24,7 +24,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. import Cocoa -@objc class AppleKeyboardConverter: NSObject { +class AppleKeyboardConverter: NSObject { static let arrDynamicBasicKeyLayout: [String] = [ "com.apple.keylayout.ZhuyinBopomofo", "com.apple.keylayout.ZhuyinEten", @@ -40,13 +40,13 @@ import Cocoa "org.unknown.keylayout.vChewingMiTAC", ] @objc class func isDynamicBasicKeyboardLayoutEnabled() -> Bool { - return AppleKeyboardConverter.arrDynamicBasicKeyLayout.contains(mgrPrefs.basicKeyboardLayout) + AppleKeyboardConverter.arrDynamicBasicKeyLayout.contains(mgrPrefs.basicKeyboardLayout) } // 處理 Apple 注音鍵盤佈局類型。 @objc class func cnvApple2ABC(_ charCode: UniChar) -> UniChar { var charCode = charCode // 在按鍵資訊被送往 OVMandarin 之前,先轉換為可以被 OVMandarin 正常處理的資訊。 - if self.isDynamicBasicKeyboardLayoutEnabled() { + if isDynamicBasicKeyboardLayoutEnabled() { // 針對不同的 Apple 動態鍵盤佈局糾正大寫英文輸入。 switch mgrPrefs.basicKeyboardLayout { case "com.apple.keylayout.ZhuyinBopomofo": @@ -186,7 +186,7 @@ import Cocoa @objc class func cnvStringApple2ABC(_ strProcessed: String) -> String { var strProcessed = strProcessed - if self.isDynamicBasicKeyboardLayoutEnabled() { + if isDynamicBasicKeyboardLayoutEnabled() { // 針對不同的 Apple 動態鍵盤佈局糾正大寫英文輸入。 switch mgrPrefs.basicKeyboardLayout { case "com.apple.keylayout.ZhuyinBopomofo": diff --git a/Source/Modules/ControllerModules/InputState.swift b/Source/Modules/ControllerModules/InputState.swift index 7ea21974..f52c149a 100644 --- a/Source/Modules/ControllerModules/InputState.swift +++ b/Source/Modules/ControllerModules/InputState.swift @@ -410,7 +410,7 @@ class InputState: NSObject { } -@objc class SymbolNode: NSObject { +class SymbolNode: NSObject { @objc var title: String @objc var children: [SymbolNode]? @@ -422,7 +422,7 @@ class InputState: NSObject { @objc init(_ title: String, symbols: String) { self.title = title - self.children = Array(symbols).map { SymbolNode(String($0), nil) } + children = Array(symbols).map { SymbolNode(String($0), nil) } super.init() } diff --git a/Source/Modules/ControllerModules/KeyParser.swift b/Source/Modules/ControllerModules/KeyParser.swift index 14b97995..bd06ec0a 100644 --- a/Source/Modules/ControllerModules/KeyParser.swift +++ b/Source/Modules/ControllerModules/KeyParser.swift @@ -116,7 +116,7 @@ class keyParser: NSObject { self.inputText = inputText self.inputTextIgnoringModifiers = inputTextIgnoringModifiers self.flags = flags - self.isFlagChanged = false + isFlagChanged = false useVerticalMode = isVerticalMode self.keyCode = keyCode self.charCode = AppleKeyboardConverter.cnvApple2ABC(charCode) @@ -295,7 +295,7 @@ class keyParser: NSObject { @objc var isUpperCaseASCIILetterKey: Bool { // 這裡必須加上「flags == .shift」,否則會出現某些情況下輸入法「誤判當前鍵入的非 Shift 字符為大寫」的問題。 - self.charCode >= 65 && self.charCode <= 90 && flags == .shift + charCode >= 65 && charCode <= 90 && flags == .shift } @objc var isSymbolMenuPhysicalKey: Bool { diff --git a/Source/Modules/ControllerModules/vChewingKanjiConverter.swift b/Source/Modules/ControllerModules/vChewingKanjiConverter.swift index 70572011..0504d382 100644 --- a/Source/Modules/ControllerModules/vChewingKanjiConverter.swift +++ b/Source/Modules/ControllerModules/vChewingKanjiConverter.swift @@ -30,7 +30,7 @@ extension String { } } -@objc class vChewingKanjiConverter: NSObject { +class vChewingKanjiConverter: NSObject { @objc class func cnvTradToKangXi(_ strObj: String) -> String { var strObj = strObj strObj.selfReplace("偽", "僞") diff --git a/Source/Modules/FileHandlers/FSEventStreamHelper.swift b/Source/Modules/FileHandlers/FSEventStreamHelper.swift index 994aeede..406a018c 100644 --- a/Source/Modules/FileHandlers/FSEventStreamHelper.swift +++ b/Source/Modules/FileHandlers/FSEventStreamHelper.swift @@ -44,7 +44,7 @@ public class FSEventStreamHelper: NSObject { @objc public init(path: String, queue: DispatchQueue) { self.path = path - self.dispatchQueue = queue + dispatchQueue = queue } private var stream: FSEventStreamRef? diff --git a/Source/Modules/IMEModules/IME.swift b/Source/Modules/IMEModules/IME.swift index 2616ca25..f137073f 100644 --- a/Source/Modules/IMEModules/IME.swift +++ b/Source/Modules/IMEModules/IME.swift @@ -25,7 +25,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. import Carbon import Cocoa -@objc public class IME: NSObject { +public class IME: NSObject { static let arrSupportedLocales = ["en", "zh-Hant", "zh-Hans", "ja"] static let dlgOpenPath = NSOpenPanel() @@ -34,7 +34,7 @@ import Cocoa // MARK: - 自 ctlInputMethod 讀取當前輸入法的簡繁體模式 static func getInputMode() -> InputMode { - return ctlInputMethod.currentKeyHandler.inputMode + ctlInputMethod.currentKeyHandler.inputMode } // MARK: - Print debug information to the console. @@ -333,13 +333,15 @@ extension RangeReplaceableCollection where Element: Hashable { // MARK: - Error Extension extension String: Error {} extension String: LocalizedError { - public var errorDescription: String? { return self } + public var errorDescription: String? { + self + } } // MARK: - Ensuring trailing slash of a string: extension String { mutating func ensureTrailingSlash() { - if !self.hasSuffix("/") { + if !hasSuffix("/") { self += "/" } } diff --git a/Source/Modules/IMEModules/ctlInputMethod.swift b/Source/Modules/IMEModules/ctlInputMethod.swift index afb63f02..764f3804 100644 --- a/Source/Modules/IMEModules/ctlInputMethod.swift +++ b/Source/Modules/IMEModules/ctlInputMethod.swift @@ -400,7 +400,7 @@ extension ctlInputMethod { return true } candidates.sort { - return $0.count > $1.count + $0.count > $1.count } // If there is a candidate which is too long, we use the vertical // candidate list window automatically. diff --git a/Source/Modules/IMEModules/mgrPrefs.swift b/Source/Modules/IMEModules/mgrPrefs.swift index b865c979..9f42bb35 100644 --- a/Source/Modules/IMEModules/mgrPrefs.swift +++ b/Source/Modules/IMEModules/mgrPrefs.swift @@ -81,7 +81,7 @@ private let kDefaultKeys = "123456789" @objc extension UserDefaults { func setDefault(_ value: Any?, forKey defaultName: String) { - if self.object(forKey: defaultName) == nil { + if object(forKey: defaultName) == nil { self.set(value, forKey: defaultName) } } @@ -200,7 +200,7 @@ struct ComposingBufferSize { } // MARK: - -@objc public class mgrPrefs: NSObject { +public class mgrPrefs: NSObject { static var allKeys: [String] { [ UserDef.kIsDebugModeEnabled, @@ -293,7 +293,7 @@ struct ComposingBufferSize { @objc static var mandarinParser: Int @objc static var mandarinParserName: String { - (MandarinParser(rawValue: self.mandarinParser) ?? MandarinParser.ofStandard).name + (MandarinParser(rawValue: mandarinParser) ?? MandarinParser.ofStandard).name } @UserDefault( @@ -372,7 +372,7 @@ struct ComposingBufferSize { chineseConversionEnabled = !chineseConversionEnabled // 康熙轉換與 JIS 轉換不能同時開啟,否則會出現某些奇奇怪怪的情況 if chineseConversionEnabled && shiftJISShinjitaiOutputEnabled { - self.toggleShiftJISShinjitaiOutputEnabled() + toggleShiftJISShinjitaiOutputEnabled() UserDefaults.standard.set( shiftJISShinjitaiOutputEnabled, forKey: UserDef.kShiftJISShinjitaiOutputEnabled) } @@ -387,7 +387,7 @@ struct ComposingBufferSize { shiftJISShinjitaiOutputEnabled = !shiftJISShinjitaiOutputEnabled // 康熙轉換與 JIS 轉換不能同時開啟,否則會出現某些奇奇怪怪的情況 if shiftJISShinjitaiOutputEnabled && chineseConversionEnabled { - self.toggleChineseConversionEnabled() + toggleChineseConversionEnabled() } UserDefaults.standard.set( shiftJISShinjitaiOutputEnabled, forKey: UserDef.kShiftJISShinjitaiOutputEnabled) diff --git a/Source/Modules/LangModelRelated/mgrLangModel.swift b/Source/Modules/LangModelRelated/mgrLangModel.swift index 9b99890a..140a0a5c 100644 --- a/Source/Modules/LangModelRelated/mgrLangModel.swift +++ b/Source/Modules/LangModelRelated/mgrLangModel.swift @@ -28,7 +28,7 @@ import Cocoa // MARK: - 獲取當前輸入法封包內的原廠核心語彙檔案所在路徑 static func getBundleDataPath(_ filenameSansExt: String) -> String { - return Bundle.main.path(forResource: filenameSansExt, ofType: "txt")! + Bundle.main.path(forResource: filenameSansExt, ofType: "txt")! } // MARK: - 使用者語彙檔案的具體檔案名稱路徑定義 @@ -36,27 +36,27 @@ import Cocoa static func userPhrasesDataPath(_ mode: InputMode) -> String { let fileName = (mode == InputMode.imeModeCHT) ? "userdata-cht.txt" : "userdata-chs.txt" - return URL(fileURLWithPath: self.dataFolderPath(isDefaultFolder: false)).appendingPathComponent(fileName).path + return URL(fileURLWithPath: dataFolderPath(isDefaultFolder: false)).appendingPathComponent(fileName).path } static func userSymbolDataPath(_ mode: InputMode) -> String { let fileName = (mode == InputMode.imeModeCHT) ? "usersymbolphrases-cht.txt" : "usersymbolphrases-chs.txt" - return URL(fileURLWithPath: self.dataFolderPath(isDefaultFolder: false)).appendingPathComponent(fileName).path + return URL(fileURLWithPath: dataFolderPath(isDefaultFolder: false)).appendingPathComponent(fileName).path } static func userAssociatedPhrasesDataPath(_ mode: InputMode) -> String { let fileName = (mode == InputMode.imeModeCHT) ? "associatedPhrases-cht.txt" : "associatedPhrases-chs.txt" - return URL(fileURLWithPath: self.dataFolderPath(isDefaultFolder: false)).appendingPathComponent(fileName).path + return URL(fileURLWithPath: dataFolderPath(isDefaultFolder: false)).appendingPathComponent(fileName).path } static func excludedPhrasesDataPath(_ mode: InputMode) -> String { let fileName = (mode == InputMode.imeModeCHT) ? "exclude-phrases-cht.txt" : "exclude-phrases-chs.txt" - return URL(fileURLWithPath: self.dataFolderPath(isDefaultFolder: false)).appendingPathComponent(fileName).path + return URL(fileURLWithPath: dataFolderPath(isDefaultFolder: false)).appendingPathComponent(fileName).path } static func phraseReplacementDataPath(_ mode: InputMode) -> String { let fileName = (mode == InputMode.imeModeCHT) ? "phrases-replacement-cht.txt" : "phrases-replacement-chs.txt" - return URL(fileURLWithPath: self.dataFolderPath(isDefaultFolder: false)).appendingPathComponent(fileName).path + return URL(fileURLWithPath: dataFolderPath(isDefaultFolder: false)).appendingPathComponent(fileName).path } // MARK: - 檢查具體的使用者語彙檔案是否存在 @@ -86,7 +86,7 @@ import Cocoa } static func chkUserLMFilesExist(_ mode: InputMode) -> Bool { - if !self.checkIfUserDataFolderExists() { + if !checkIfUserDataFolderExists() { return false } if !ensureFileExists(userPhrasesDataPath(mode)) @@ -136,8 +136,8 @@ import Cocoa // 如果要找的目標路徑不是原廠目標路徑的話,則直接報錯。 if folderExist && !isFolder.boolValue { do { - if self.dataFolderPath(isDefaultFolder: false) - == self.dataFolderPath(isDefaultFolder: true) + if dataFolderPath(isDefaultFolder: false) + == dataFolderPath(isDefaultFolder: true) { let formatter = DateFormatter.init() formatter.dateFormat = "YYYYMMDD-HHMM'Hrs'-ss's'" @@ -199,13 +199,13 @@ import Cocoa _ userPhrase: String?, inputMode mode: InputMode, areWeDuplicating: Bool, areWeDeleting: Bool ) -> Bool { if var currentMarkedPhrase: String = userPhrase { - if !self.chkUserLMFilesExist(InputMode.imeModeCHS) - || !self.chkUserLMFilesExist(InputMode.imeModeCHT) + if !chkUserLMFilesExist(InputMode.imeModeCHS) + || !chkUserLMFilesExist(InputMode.imeModeCHT) { return false } - let path = areWeDeleting ? self.excludedPhrasesDataPath(mode) : self.userPhrasesDataPath(mode) + let path = areWeDeleting ? excludedPhrasesDataPath(mode) : userPhrasesDataPath(mode) if areWeDuplicating && !areWeDeleting { // Do not use ASCII characters to comment here. @@ -227,12 +227,12 @@ import Cocoa // We enforce the format consolidation here, since the pragma header // will let the UserPhraseLM bypasses the consolidating process on load. - self.consolidate(givenFile: path, shouldCheckPragma: false) + consolidate(givenFile: path, shouldCheckPragma: false) // We use FSEventStream to monitor possible changes of the user phrase folder, hence the // lack of the needs of manually load data here unless FSEventStream is disabled by user. if !mgrPrefs.shouldAutoReloadUserDataFiles { - self.loadUserPhrases() + loadUserPhrases() } return true } diff --git a/Source/Modules/SFX/clsSFX.swift b/Source/Modules/SFX/clsSFX.swift index 2b8b55dc..faf5e5c6 100644 --- a/Source/Modules/SFX/clsSFX.swift +++ b/Source/Modules/SFX/clsSFX.swift @@ -26,7 +26,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. import Cocoa -@objc public class clsSFX: NSObject, NSSoundDelegate { +public class clsSFX: NSObject, NSSoundDelegate { private static let shared = clsSFX() private override init() { super.init() diff --git a/Source/UI/CandidateUI/ctlCandidateHorizontal.swift b/Source/UI/CandidateUI/ctlCandidateHorizontal.swift index e2e78b23..687b012b 100644 --- a/Source/UI/CandidateUI/ctlCandidateHorizontal.swift +++ b/Source/UI/CandidateUI/ctlCandidateHorizontal.swift @@ -116,7 +116,7 @@ private class HorizontalCandidateView: NSView { } override func draw(_ dirtyRect: NSRect) { - let bounds = self.bounds + let bounds = bounds NSColor.controlBackgroundColor.setFill() // Candidate list panel base background NSBezierPath.fill(bounds) @@ -190,7 +190,7 @@ private class HorizontalCandidateView: NSView { private func findHitIndex(event: NSEvent) -> UInt? { let location = convert(event.locationInWindow, to: nil) - if !NSPointInRect(location, self.bounds) { + if !bounds.contains(location) { return nil } var accuWidth: CGFloat = 0.0 @@ -212,7 +212,7 @@ private class HorizontalCandidateView: NSView { return } highlightedIndex = newIndex - self.setNeedsDisplay(self.bounds) + setNeedsDisplay(bounds) } override func mouseDown(with event: NSEvent) { @@ -227,7 +227,7 @@ private class HorizontalCandidateView: NSView { } trackingHighlightedIndex = 0 - self.setNeedsDisplay(self.bounds) + setNeedsDisplay(bounds) if triggerAction { if let target = target as? NSObject, let action = action { target.perform(action, with: self) @@ -236,7 +236,7 @@ private class HorizontalCandidateView: NSView { } } -@objc public class ctlCandidateHorizontal: ctlCandidate { +public class ctlCandidateHorizontal: ctlCandidate { private var candidateView: HorizontalCandidateView private var prevPageButton: NSButton private var nextPageButton: NSButton @@ -438,7 +438,7 @@ extension ctlCandidateHorizontal { let topLeftPoint = NSPoint(x: frameRect.origin.x, y: frameRect.origin.y + frameRect.size.height) frameRect.size = newSize frameRect.origin = NSPoint(x: topLeftPoint.x, y: topLeftPoint.y - frameRect.size.height) - self.window?.setFrame(frameRect, display: false) + window?.setFrame(frameRect, display: false) candidateView.setNeedsDisplay(candidateView.bounds) } diff --git a/Source/UI/CandidateUI/ctlCandidateVertical.swift b/Source/UI/CandidateUI/ctlCandidateVertical.swift index dfeb93f7..69de51a8 100644 --- a/Source/UI/CandidateUI/ctlCandidateVertical.swift +++ b/Source/UI/CandidateUI/ctlCandidateVertical.swift @@ -122,7 +122,7 @@ private class VerticalCandidateView: NSView { } override func draw(_ dirtyRect: NSRect) { - let bounds = self.bounds + let bounds = bounds NSColor.controlBackgroundColor.setFill() // Candidate list panel base background NSBezierPath.fill(bounds) @@ -195,7 +195,7 @@ private class VerticalCandidateView: NSView { private func findHitIndex(event: NSEvent) -> UInt? { let location = convert(event.locationInWindow, to: nil) - if !NSPointInRect(location, self.bounds) { + if !bounds.contains(location) { return nil } var accuHeight: CGFloat = 0.0 @@ -217,7 +217,7 @@ private class VerticalCandidateView: NSView { return } highlightedIndex = newIndex - self.setNeedsDisplay(self.bounds) + setNeedsDisplay(bounds) } override func mouseDown(with event: NSEvent) { @@ -232,7 +232,7 @@ private class VerticalCandidateView: NSView { } trackingHighlightedIndex = 0 - self.setNeedsDisplay(self.bounds) + setNeedsDisplay(bounds) if triggerAction { if let target = target as? NSObject, let action = action { target.perform(action, with: self) @@ -241,7 +241,7 @@ private class VerticalCandidateView: NSView { } } -@objc public class ctlCandidateVertical: ctlCandidate { +public class ctlCandidateVertical: ctlCandidate { private var candidateView: VerticalCandidateView private var prevPageButton: NSButton private var nextPageButton: NSButton @@ -443,7 +443,7 @@ extension ctlCandidateVertical { let topLeftPoint = NSPoint(x: frameRect.origin.x, y: frameRect.origin.y + frameRect.size.height) frameRect.size = newSize frameRect.origin = NSPoint(x: topLeftPoint.x, y: topLeftPoint.y - frameRect.size.height) - self.window?.setFrame(frameRect, display: false) + window?.setFrame(frameRect, display: false) candidateView.setNeedsDisplay(candidateView.bounds) } diff --git a/Source/UI/NotifierUI/NotifierController.swift b/Source/UI/NotifierUI/NotifierController.swift index a99302d9..4ca8f3a0 100644 --- a/Source/UI/NotifierUI/NotifierController.swift +++ b/Source/UI/NotifierUI/NotifierController.swift @@ -69,12 +69,12 @@ public class NotifierController: NSWindowController, NotifierWindowDelegate { private var shouldStay: Bool = false private var backgroundColor: NSColor = .textBackgroundColor { didSet { - self.window?.backgroundColor = backgroundColor + window?.backgroundColor = backgroundColor } } private var foregroundColor: NSColor = .controlTextColor { didSet { - self.messageTextField.textColor = foregroundColor + messageTextField.textColor = foregroundColor } } private var waitTimer: Timer? @@ -155,7 +155,7 @@ public class NotifierController: NSWindowController, NotifierWindowDelegate { } let lastLocation = NotifierController.lastLocation let screenRect = NSScreen.main?.visibleFrame ?? NSRect.zero - var windowRect = self.window?.frame ?? NSRect.zero + var windowRect = window?.frame ?? NSRect.zero windowRect.origin.x = lastLocation.x windowRect.origin.y = lastLocation.y - 10 - windowRect.height @@ -163,11 +163,11 @@ public class NotifierController: NSWindowController, NotifierWindowDelegate { return } - self.window?.setFrame(windowRect, display: true) + window?.setFrame(windowRect, display: true) } func moveIn() { - let afterRect = self.window?.frame ?? NSRect.zero + let afterRect = window?.frame ?? NSRect.zero NotifierController.lastLocation = afterRect.origin var beforeRect = afterRect beforeRect.origin.y += 10 @@ -186,11 +186,11 @@ public class NotifierController: NSWindowController, NotifierWindowDelegate { } @objc private func doFadeOut(_ timer: Timer) { - let opacity = self.window?.alphaValue ?? 0 + let opacity = window?.alphaValue ?? 0 if opacity <= 0 { - self.close() + close() } else { - self.window?.alphaValue = opacity - 0.2 + window?.alphaValue = opacity - 0.2 } } @@ -212,6 +212,6 @@ public class NotifierController: NSWindowController, NotifierWindowDelegate { } fileprivate func windowDidBecomeClicked(_ window: NotifierWindow) { - self.fadeOut() + fadeOut() } } diff --git a/Source/WindowControllers/ctlPrefWindow.swift b/Source/WindowControllers/ctlPrefWindow.swift index 96d8f19f..3152bbfa 100644 --- a/Source/WindowControllers/ctlPrefWindow.swift +++ b/Source/WindowControllers/ctlPrefWindow.swift @@ -264,8 +264,8 @@ import Cocoa let bolPreviousFolderValidity = mgrLangModel.checkIfSpecifiedUserDataFolderValid( NSString(string: mgrPrefs.userDataFolderSpecified).expandingTildeInPath) - if self.window != nil { - IME.dlgOpenPath.beginSheetModal(for: self.window!) { result in + if window != nil { + IME.dlgOpenPath.beginSheetModal(for: window!) { result in if result == NSApplication.ModalResponse.OK { if IME.dlgOpenPath.url != nil { // CommonDialog 讀入的路徑沒有結尾斜槓,這會導致檔案目錄合規性判定失準。 diff --git a/UserPhraseEditor/AppDelegate.swift b/UserPhraseEditor/AppDelegate.swift index e5e44d25..32b4f840 100644 --- a/UserPhraseEditor/AppDelegate.swift +++ b/UserPhraseEditor/AppDelegate.swift @@ -38,7 +38,7 @@ class AppDelegate: NSObject, NSApplicationDelegate { } func applicationShouldTerminate(_ sender: NSApplication) -> NSApplication.TerminateReply { - return .terminateNow + .terminateNow } // New About Window @objc func showAbout() { diff --git a/UserPhraseEditor/Content.swift b/UserPhraseEditor/Content.swift index 3cf4acf6..d32656fd 100644 --- a/UserPhraseEditor/Content.swift +++ b/UserPhraseEditor/Content.swift @@ -41,7 +41,7 @@ extension Content { } func data() -> Data? { - return contentString.data(using: .utf8) + contentString.data(using: .utf8) } } diff --git a/UserPhraseEditor/Document.swift b/UserPhraseEditor/Document.swift index 6777e77f..e455f186 100644 --- a/UserPhraseEditor/Document.swift +++ b/UserPhraseEditor/Document.swift @@ -38,19 +38,19 @@ class Document: NSDocument { // This enables auto save. override class var autosavesInPlace: Bool { - return true + true } // This enables asynchronous-writing. override func canAsynchronouslyWrite( to url: URL, ofType typeName: String, for saveOperation: NSDocument.SaveOperationType ) -> Bool { - return true + true } // This enables asynchronous reading. override class func canConcurrentlyReadDocuments(ofType: String) -> Bool { - return ofType == "public.plain-text" + ofType == "public.plain-text" } // MARK: - User Interface diff --git a/UserPhraseEditor/StringExtension.swift b/UserPhraseEditor/StringExtension.swift index bc6aa222..e6a226c3 100644 --- a/UserPhraseEditor/StringExtension.swift +++ b/UserPhraseEditor/StringExtension.swift @@ -30,7 +30,7 @@ extension String { do { let regex = try NSRegularExpression( pattern: pattern, options: [.caseInsensitive, .anchorsMatchLines]) - let range = NSRange(self.startIndex..., in: self) + let range = NSRange(startIndex..., in: self) self = regex.stringByReplacingMatches( in: self, options: [], range: range, withTemplate: replaceWith) } catch { return }