From e68fa10c429ee65f549d61f4c4d7fa0e3956d171 Mon Sep 17 00:00:00 2001 From: Serg Date: Thu, 17 Oct 2019 23:23:24 +0700 Subject: [PATCH] update swift to 5.0 --- MTMR.xcodeproj/project.pbxproj | 12 ++++++------ MTMR/AppDelegate.swift | 4 ++-- MTMR/TouchBarController.swift | 2 +- MTMR/Widgets/AppScrubberTouchBarItem.swift | 4 ++-- MTMR/Widgets/NetworkBarItem.swift | 10 ++++++---- 5 files changed, 17 insertions(+), 15 deletions(-) diff --git a/MTMR.xcodeproj/project.pbxproj b/MTMR.xcodeproj/project.pbxproj index 603b705..c5b31ff 100644 --- a/MTMR.xcodeproj/project.pbxproj +++ b/MTMR.xcodeproj/project.pbxproj @@ -362,7 +362,7 @@ TargetAttributes = { B082B24E205C7D8000BC04DC = { CreatedOnToolsVersion = 9.2; - LastSwiftMigration = 1000; + LastSwiftMigration = 1020; ProvisioningStyle = Manual; SystemCapabilities = { com.apple.Sandbox = { @@ -372,7 +372,7 @@ }; B082B260205C7D8000BC04DC = { CreatedOnToolsVersion = 9.2; - LastSwiftMigration = 1000; + LastSwiftMigration = 1020; }; }; }; @@ -640,7 +640,7 @@ PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE_SPECIFIER = ""; SWIFT_OBJC_BRIDGING_HEADER = "MTMR/CBridge/TouchBarPrivateApi-Bridging.h"; - SWIFT_VERSION = 4.2; + SWIFT_VERSION = 5.0; }; name = Debug; }; @@ -663,7 +663,7 @@ PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE_SPECIFIER = ""; SWIFT_OBJC_BRIDGING_HEADER = "MTMR/CBridge/TouchBarPrivateApi-Bridging.h"; - SWIFT_VERSION = 4.2; + SWIFT_VERSION = 5.0; }; name = Release; }; @@ -676,7 +676,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = Toxblh.MTMRTests; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 4.2; + SWIFT_VERSION = 5.0; }; name = Debug; }; @@ -691,7 +691,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = Toxblh.MTMRTests; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 4.2; + SWIFT_VERSION = 5.0; }; name = Release; }; diff --git a/MTMR/AppDelegate.swift b/MTMR/AppDelegate.swift index 08932de..0c9c060 100644 --- a/MTMR/AppDelegate.swift +++ b/MTMR/AppDelegate.swift @@ -56,7 +56,7 @@ class AppDelegate: NSObject, NSApplicationDelegate { } if frontmostApplicationIdentifier != nil { - isBlockedApp = blacklistAppIdentifiers.index(of: frontmostApplicationIdentifier!) != nil + isBlockedApp = blacklistAppIdentifiers.firstIndex(of: frontmostApplicationIdentifier!) != nil } else { isBlockedApp = false } @@ -81,7 +81,7 @@ class AppDelegate: NSObject, NSApplicationDelegate { @objc func toggleBlackListedApp(_: Any?) { let appIdentifier = TouchBarController.shared.frontmostApplicationIdentifier if appIdentifier != nil { - if let index = TouchBarController.shared.blacklistAppIdentifiers.index(of: appIdentifier!) { + if let index = TouchBarController.shared.blacklistAppIdentifiers.firstIndex(of: appIdentifier!) { TouchBarController.shared.blacklistAppIdentifiers.remove(at: index) } else { TouchBarController.shared.blacklistAppIdentifiers.append(appIdentifier!) diff --git a/MTMR/TouchBarController.swift b/MTMR/TouchBarController.swift index 0900052..a56e8c9 100644 --- a/MTMR/TouchBarController.swift +++ b/MTMR/TouchBarController.swift @@ -161,7 +161,7 @@ class TouchBarController: NSObject, NSTouchBarDelegate { } func updateActiveApp() { - if frontmostApplicationIdentifier != nil && blacklistAppIdentifiers.index(of: frontmostApplicationIdentifier!) != nil { + if frontmostApplicationIdentifier != nil && blacklistAppIdentifiers.firstIndex(of: frontmostApplicationIdentifier!) != nil { dismissTouchBar() } else { presentTouchBar() diff --git a/MTMR/Widgets/AppScrubberTouchBarItem.swift b/MTMR/Widgets/AppScrubberTouchBarItem.swift index 51043da..0466be7 100644 --- a/MTMR/Widgets/AppScrubberTouchBarItem.swift +++ b/MTMR/Widgets/AppScrubberTouchBarItem.swift @@ -80,7 +80,7 @@ class AppScrubberTouchBarItem: NSCustomTouchBarItem, NSScrubberDelegate, NSScrub func updateRunningApplication() { let newApplications = launchedApplications() - let index = newApplications.index { + let index = newApplications.firstIndex { $0.bundleIdentifier == frontmostApplicationIdentifier } @@ -202,7 +202,7 @@ class AppScrubberTouchBarItem: NSCustomTouchBarItem, NSScrubberDelegate, NSScrub } } else { HapticFeedback.shared?.tap(strong: 6) - if let index = self.persistentAppIdentifiers.index(of: bundleIdentifier!) { + if let index = self.persistentAppIdentifiers.firstIndex(of: bundleIdentifier!) { persistentAppIdentifiers.remove(at: index) } else { persistentAppIdentifiers.append(bundleIdentifier!) diff --git a/MTMR/Widgets/NetworkBarItem.swift b/MTMR/Widgets/NetworkBarItem.swift index 21c5820..57de0bf 100644 --- a/MTMR/Widgets/NetworkBarItem.swift +++ b/MTMR/Widgets/NetworkBarItem.swift @@ -31,7 +31,7 @@ class NetworkBarItem: CustomButtonTouchBarItem, Widget { var dSpeed: UInt64? var uSpeed: UInt64? var curr: Array? - var dataAvailable: NSObjectProtocol! + var dataAvailable: NSObjectProtocol? pipe = Pipe() bandwidthProcess = Process() @@ -64,19 +64,21 @@ class NetworkBarItem: CustomButtonTouchBarItem, Widget { } } outputHandle.waitForDataInBackgroundAndNotify() - } else { + } else if let dataAvailable = dataAvailable { NotificationCenter.default.removeObserver(dataAvailable) } } - var dataReady: NSObjectProtocol! + var dataReady: NSObjectProtocol? dataReady = NotificationCenter.default.addObserver( forName: Process.didTerminateNotification, object: outputHandle, queue: nil ) { _ -> Void in print("Task terminated!") - NotificationCenter.default.removeObserver(dataReady) + if let observer = dataReady { + NotificationCenter.default.removeObserver(observer) + } } bandwidthProcess?.launch()