diff --git a/Aware.xcodeproj/project.pbxproj b/Aware.xcodeproj/project.pbxproj index d6fcde1..1e8da02 100644 --- a/Aware.xcodeproj/project.pbxproj +++ b/Aware.xcodeproj/project.pbxproj @@ -7,7 +7,6 @@ objects = { /* Begin PBXBuildFile section */ - 0337E7871C14E37B003A8150 /* Timer+Block.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0337E7861C14E37B003A8150 /* Timer+Block.swift */; }; 036EBD191C1408C200121D0B /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 036EBD181C1408C200121D0B /* AppDelegate.swift */; }; 036EBD1B1C1408C200121D0B /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 036EBD1A1C1408C200121D0B /* Assets.xcassets */; }; 036EBD1E1C1408C200121D0B /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = 036EBD1C1C1408C200121D0B /* MainMenu.xib */; }; @@ -26,7 +25,6 @@ /* End PBXContainerItemProxy section */ /* Begin PBXFileReference section */ - 0337E7861C14E37B003A8150 /* Timer+Block.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Timer+Block.swift"; sourceTree = ""; }; 036EBD151C1408C200121D0B /* Aware.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Aware.app; sourceTree = BUILT_PRODUCTS_DIR; }; 036EBD181C1408C200121D0B /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 036EBD1A1C1408C200121D0B /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; @@ -78,7 +76,6 @@ children = ( 036EBD181C1408C200121D0B /* AppDelegate.swift */, 03F9E2301C24CCA8001DBE86 /* NSTimeIntervalFormatter.swift */, - 0337E7861C14E37B003A8150 /* Timer+Block.swift */, 036EBD1A1C1408C200121D0B /* Assets.xcassets */, 036EBD1C1C1408C200121D0B /* MainMenu.xib */, 038D0B381C4DDD5600040C44 /* Aware.entitlements */, @@ -207,7 +204,6 @@ files = ( 03F9E2311C24CCA8001DBE86 /* NSTimeIntervalFormatter.swift in Sources */, 036EBD191C1408C200121D0B /* AppDelegate.swift in Sources */, - 0337E7871C14E37B003A8150 /* Timer+Block.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/Aware/AppDelegate.swift b/Aware/AppDelegate.swift index e06fc70..9df14da 100644 --- a/Aware/AppDelegate.swift +++ b/Aware/AppDelegate.swift @@ -45,7 +45,7 @@ class AppDelegate: NSObject, NSApplicationDelegate { statusItem.menu = menu updateButton() - _ = Timer.scheduledTimer(buttonRefreshRate, userInfo: nil, repeats: true) { _ in self.updateButton() } + _ = Timer.scheduledTimer(withTimeInterval: buttonRefreshRate, repeats: true) { _ in self.updateButton() } let notificationCenter = NSWorkspace.shared.notificationCenter notificationCenter.addObserver(forName: NSWorkspace.willSleepNotification, object: nil, queue: nil) { _ in self.resetTimer() } diff --git a/Aware/Timer+Block.swift b/Aware/Timer+Block.swift deleted file mode 100644 index 618bf33..0000000 --- a/Aware/Timer+Block.swift +++ /dev/null @@ -1,60 +0,0 @@ -// -// Timer+Block.swift -// Aware -// -// Created by Joshua Peek on 12/06/15. -// Copyright © 2015 Joshua Peek. -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -import Foundation - -// Alternative API for timer creation with a block. -// Inspired by proposed Swift corelib interface: -// https://github.com/apple/swift-corelibs-foundation/blob/7836f63/Foundation/NSTimer.swift#L52-L60 -extension Timer { - private class TimerHandler { - let _fire: (Timer) -> Void - - init(_ fire: @escaping (Timer) -> Void) { - _fire = fire - } - - @objc func fire(_ timer: Timer) { - _fire(timer) - } - } - - /** - Creates and returns a new `Timer` object and schedules it on the current run loop in the default mode. - - - Parameters: - - seconds: The number of seconds between firings of the timer. If seconds is less than or equal to 0.0, this method chooses the nonnegative value of 0.1 milliseconds instead. - - userInfo: The user info for the timer. The timer maintains a strong reference to this object until it (the timer) is invalidated. This parameter may be nil. - - repeats: If true, the timer will repeatedly reschedule itself until invalidated. If false, the timer will be invalidated after it fires. - - fire: The block to call when the timer fires. The timer maintains a strong reference to target until it (the timer) is invalidated. - - - Returns: A new `Timer` object, configured according to the specified parameters. - */ - public class func scheduledTimer(_ ti: TimeInterval, userInfo: AnyObject?, repeats: Bool, fire: @escaping (Timer) -> Void) -> Timer { - return Timer.scheduledTimer(timeInterval: ti, target: TimerHandler(fire), selector: #selector(TimerHandler.fire(_:)), userInfo: userInfo, repeats: repeats) - } -}