Skip to content

Commit

Permalink
update to swift 4, and update version
Browse files Browse the repository at this point in the history
  • Loading branch information
fireph committed Oct 5, 2017
1 parent 2aad548 commit 91ba2e9
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 55 deletions.
32 changes: 19 additions & 13 deletions TrafficSweetSpot.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -232,16 +232,16 @@
TargetAttributes = {
FA70FCC01D3EA484008BF487 = {
CreatedOnToolsVersion = 7.3.1;
LastSwiftMigration = 0830;
LastSwiftMigration = 0900;
};
FA70FCCF1D3EA484008BF487 = {
CreatedOnToolsVersion = 7.3.1;
LastSwiftMigration = 0830;
LastSwiftMigration = 0900;
TestTargetID = FA70FCC01D3EA484008BF487;
};
FA70FCDA1D3EA484008BF487 = {
CreatedOnToolsVersion = 7.3.1;
LastSwiftMigration = 0830;
LastSwiftMigration = 0900;
TestTargetID = FA70FCC01D3EA484008BF487;
};
};
Expand Down Expand Up @@ -419,7 +419,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
MACOSX_DEPLOYMENT_TARGET = 10.11;
MACOSX_DEPLOYMENT_TARGET = 10.12;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = macosx;
Expand Down Expand Up @@ -466,7 +466,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
MACOSX_DEPLOYMENT_TARGET = 10.11;
MACOSX_DEPLOYMENT_TARGET = 10.12;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = macosx;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
Expand All @@ -484,10 +484,11 @@
);
INFOPLIST_FILE = TrafficSweetSpot/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks";
MACOSX_DEPLOYMENT_TARGET = 10.11;
MACOSX_DEPLOYMENT_TARGET = 10.12;
PRODUCT_BUNDLE_IDENTIFIER = com.fmeyer.TrafficSweetSpot;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
SWIFT_VERSION = 4.0;
};
name = Debug;
};
Expand All @@ -502,10 +503,11 @@
);
INFOPLIST_FILE = TrafficSweetSpot/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks";
MACOSX_DEPLOYMENT_TARGET = 10.11;
MACOSX_DEPLOYMENT_TARGET = 10.12;
PRODUCT_BUNDLE_IDENTIFIER = com.fmeyer.TrafficSweetSpot;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
SWIFT_VERSION = 4.0;
};
name = Release;
};
Expand All @@ -518,7 +520,8 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.fmeyer.TrafficSweetSpotTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
SWIFT_VERSION = 4.0;
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/TrafficSweetSpot.app/Contents/MacOS/TrafficSweetSpot";
};
name = Debug;
Expand All @@ -532,7 +535,8 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.fmeyer.TrafficSweetSpotTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
SWIFT_VERSION = 4.0;
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/TrafficSweetSpot.app/Contents/MacOS/TrafficSweetSpot";
};
name = Release;
Expand All @@ -545,7 +549,8 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.fmeyer.TrafficSweetSpotUITests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
SWIFT_VERSION = 4.0;
TEST_TARGET_NAME = TrafficSweetSpot;
};
name = Debug;
Expand All @@ -558,7 +563,8 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.fmeyer.TrafficSweetSpotUITests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
SWIFT_VERSION = 4.0;
TEST_TARGET_NAME = TrafficSweetSpot;
};
name = Release;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict/>
</plist>
6 changes: 3 additions & 3 deletions TrafficSweetSpot/AboutWindow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import Cocoa
class AboutWindow: NSWindowController {
@IBOutlet weak var versionText: NSTextField!

override var windowNibName : String! {
return "AboutWindow"
override var windowNibName : NSNib.Name? {
return NSNib.Name.init("AboutWindow")
}

override func windowDidLoad() {
Expand All @@ -28,7 +28,7 @@ class AboutWindow: NSWindowController {
}

@IBAction func githubClick(_ sender: AnyObject) {
NSWorkspace.shared().open(URL(string: "https://github.com/DungFu/TrafficSweetSpot")!)
NSWorkspace.shared.open(URL(string: "https://github.com/DungFu/TrafficSweetSpot")!)
self.window?.close()
}
}
4 changes: 2 additions & 2 deletions TrafficSweetSpot/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.2</string>
<string>1.3</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>3</string>
<string>4</string>
<key>LSMinimumSystemVersion</key>
<string>$(MACOSX_DEPLOYMENT_TARGET)</string>
<key>LSUIElement</key>
Expand Down
28 changes: 9 additions & 19 deletions TrafficSweetSpot/NSTextFieldWithKeyboard.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,42 +8,32 @@

import Cocoa

@objc protocol UndoActionRespondable {
func undo(_ sender: AnyObject)
}

@objc protocol RedoActionRespondable {
func redo(_ sender: AnyObject)
}

// Copied from https://stackoverflow.com/a/41200377/1815751
class NSTextFieldWithKeyboard: NSTextField {

fileprivate let commandKey = NSEventModifierFlags.command.rawValue
fileprivate let commandShiftKey = NSEventModifierFlags.command.rawValue | NSEventModifierFlags.shift.rawValue
private let commandKey = NSEvent.ModifierFlags.command.rawValue
private let commandShiftKey = NSEvent.ModifierFlags.command.rawValue | NSEvent.ModifierFlags.shift.rawValue
override func performKeyEquivalent(with event: NSEvent) -> Bool {
if event.type == NSEventType.keyDown {
if (event.modifierFlags.rawValue & NSEventModifierFlags.deviceIndependentFlagsMask.rawValue) == commandKey {
if event.type == NSEvent.EventType.keyDown {
if (event.modifierFlags.rawValue & NSEvent.ModifierFlags.deviceIndependentFlagsMask.rawValue) == commandKey {
switch event.charactersIgnoringModifiers! {
case "x":
// New Swift 2.2 #selector works for cut, copy, paste and select all
if NSApp.sendAction(#selector(NSText.cut(_:)), to:nil, from:self) { return true }
case "c":
if NSApp.sendAction(#selector(NSText.copy(_:)), to:nil, from:self) { return true }
case "v":
if NSApp.sendAction(#selector(NSText.paste(_:)), to:nil, from:self) { return true }
case "z":
let undoSelector = #selector(UndoActionRespondable.undo(_:))
if NSApp.sendAction(undoSelector, to:nil, from:self) { return true }
if NSApp.sendAction(Selector(("undo:")), to:nil, from:self) { return true }
case "a":
if NSApp.sendAction(#selector(NSText.selectAll(_:)), to:nil, from:self) { return true }
if NSApp.sendAction(#selector(NSResponder.selectAll(_:)), to:nil, from:self) { return true }
default:
break
}
}
else if (event.modifierFlags.rawValue & NSEventModifierFlags.deviceIndependentFlagsMask.rawValue) == commandShiftKey {
else if (event.modifierFlags.rawValue & NSEvent.ModifierFlags.deviceIndependentFlagsMask.rawValue) == commandShiftKey {
if event.charactersIgnoringModifiers == "Z" {
let redoSelector = #selector(RedoActionRespondable.redo(_:))
if NSApp.sendAction(redoSelector, to:nil, from:self) { return true }
if NSApp.sendAction(Selector(("redo:")), to:nil, from:self) { return true }
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions TrafficSweetSpot/PreferencesWindow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ class PreferencesWindow: NSWindowController {

var delegate: PreferencesWindowDelegate?

override var windowNibName : String! {
return "PreferencesWindow"
override var windowNibName : NSNib.Name? {
return NSNib.Name.init("PreferencesWindow")
}

override func windowDidLoad() {
Expand Down
26 changes: 13 additions & 13 deletions TrafficSweetSpot/StatusMenuController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class StatusMenuController: NSObject, PreferencesWindowDelegate {
let INTERVAL_TIME_IN_SECONDS = 300.0
let THROW_AWAY_INTERVAL_MIN = 60.0

let statusItem = NSStatusBar.system().statusItem(withLength: NSVariableStatusItemLength)
let statusItem = NSStatusBar.system.statusItem(withLength: NSStatusItem.variableLength)
let mapsAPI = MapsDistanceMatrixAPI()
let versionChecker = VersionChecker()

Expand All @@ -69,7 +69,7 @@ class StatusMenuController: NSObject, PreferencesWindowDelegate {
var routesData : LineChartData!

override func awakeFromNib() {
let icon = NSImage(named: "statusIcon")
let icon = NSImage(named: NSImage.Name(rawValue: "statusIcon"))
icon?.isTemplate = true // best for dark mode
statusItem.image = icon
statusItem.menu = statusMenu
Expand All @@ -82,11 +82,11 @@ class StatusMenuController: NSObject, PreferencesWindowDelegate {
initChartData()
updateTravelTime()
let alarm = Timer.scheduledTimer(
timeInterval: INTERVAL_TIME_IN_SECONDS,
target: self,
selector: #selector(StatusMenuController.updateTravelTime),
userInfo: nil,
repeats: true
withTimeInterval: INTERVAL_TIME_IN_SECONDS,
repeats: true,
block: { (Timer) in
self.updateTravelTime()
}
)
RunLoop.main.add(alarm, forMode: RunLoopMode.commonModes)
}
Expand Down Expand Up @@ -224,11 +224,11 @@ class StatusMenuController: NSObject, PreferencesWindowDelegate {
checkForUpdate()
checkForUpdatesTimer?.invalidate()
checkForUpdatesTimer = Timer.scheduledTimer(
timeInterval: CHECK_FOR_UPDATES_INTERVAL_DAYS*24.0*60.0*60.0,
target: self,
selector: #selector(StatusMenuController.checkForUpdate),
userInfo: nil,
repeats: true
withTimeInterval: CHECK_FOR_UPDATES_INTERVAL_DAYS*24.0*60.0*60.0,
repeats: true,
block: { (Timer) in
self.checkForUpdate()
}
)
RunLoop.main.add(checkForUpdatesTimer!, forMode: RunLoopMode.commonModes)
}
Expand All @@ -247,7 +247,7 @@ class StatusMenuController: NSObject, PreferencesWindowDelegate {
}

@IBAction func quitClicked(_ sender: NSMenuItem) {
NSApplication.shared().terminate(self)
NSApplication.shared.terminate(self)
}

func getTimestampString(_ timestamp: Double) -> String {
Expand Down
6 changes: 3 additions & 3 deletions TrafficSweetSpot/UpdateWindow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
import Cocoa

class UpdateWindow: NSWindowController {
override var windowNibName : String! {
return "UpdateWindow"
override var windowNibName : NSNib.Name? {
return NSNib.Name.init("UpdateWindow")
}

override func windowDidLoad() {
Expand All @@ -22,7 +22,7 @@ class UpdateWindow: NSWindowController {
}

@IBAction func downloadButtonClick(_ sender: AnyObject) {
NSWorkspace.shared().open(URL(string: "https://github.com/DungFu/TrafficSweetSpot/releases")!)
NSWorkspace.shared.open(URL(string: "https://github.com/DungFu/TrafficSweetSpot/releases")!)
self.window?.close()
}
}

0 comments on commit 91ba2e9

Please # to comment.