Skip to content

Commit 5047c6a

Browse files
committed
Convert to Swift 4
1 parent 970f6ef commit 5047c6a

File tree

5 files changed

+21
-18
lines changed

5 files changed

+21
-18
lines changed

ModMove.xcodeproj/project.pbxproj

+5-2
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@
126126
TargetAttributes = {
127127
C27E73161BD9FFB00058FDD0 = {
128128
CreatedOnToolsVersion = 7.1;
129+
LastSwiftMigration = 0920;
129130
};
130131
};
131132
};
@@ -287,7 +288,8 @@
287288
PRODUCT_BUNDLE_IDENTIFIER = com.smileykeith.ModMove;
288289
PRODUCT_NAME = "$(TARGET_NAME)";
289290
SWIFT_OBJC_BRIDGING_HEADER = "ModMove/Resources/ModMove-Bridging-Header.h";
290-
SWIFT_VERSION = 3.0;
291+
SWIFT_SWIFT3_OBJC_INFERENCE = Off;
292+
SWIFT_VERSION = 4.0;
291293
};
292294
name = Debug;
293295
};
@@ -302,7 +304,8 @@
302304
PRODUCT_BUNDLE_IDENTIFIER = com.smileykeith.ModMove;
303305
PRODUCT_NAME = "$(TARGET_NAME)";
304306
SWIFT_OBJC_BRIDGING_HEADER = "ModMove/Resources/ModMove-Bridging-Header.h";
305-
SWIFT_VERSION = 3.0;
307+
SWIFT_SWIFT3_OBJC_INFERENCE = Off;
308+
SWIFT_VERSION = 4.0;
306309
};
307310
name = Release;
308311
};

ModMove/AccessibilityElement.swift

+12-12
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,11 @@ final class AccessibilityElement {
4848
}
4949

5050
func parent() -> Self? {
51-
return self.value(for: kAXParentAttribute)
51+
return self.value(for: .parent)
5252
}
5353

5454
func role() -> String? {
55-
return self.value(for: kAXRoleAttribute)
55+
return self.value(for: .role)
5656
}
5757

5858
func pid() -> pid_t? {
@@ -62,24 +62,24 @@ final class AccessibilityElement {
6262
}
6363

6464
func bringToFront() {
65-
if let isMainWindow = self.rawValue(for: NSAccessibilityMainAttribute) as? Bool, isMainWindow
65+
if let isMainWindow = self.rawValue(for: .main) as? Bool, isMainWindow
6666
{
6767
return
6868
}
6969

7070
AXUIElementSetAttributeValue(self.elementRef,
71-
NSAccessibilityMainAttribute as CFString,
71+
NSAccessibilityAttributeName.main.rawValue as CFString,
7272
true as CFTypeRef)
7373
}
7474

7575
// MARK: - Private functions
7676

77-
static private func createSystemWideElement() -> Self {
77+
private static func createSystemWideElement() -> Self {
7878
return self.init(elementRef: AXUIElementCreateSystemWide())
7979
}
8080

8181
private func getPosition() -> CGPoint? {
82-
return self.value(for: kAXPositionAttribute)
82+
return self.value(for: .position)
8383
}
8484

8585
private func set(position: CGPoint) {
@@ -89,7 +89,7 @@ final class AccessibilityElement {
8989
}
9090

9191
private func getSize() -> CGSize? {
92-
return self.value(for: kAXSizeAttribute)
92+
return self.value(for: .size)
9393
}
9494

9595
private func set(size: CGSize) {
@@ -98,25 +98,25 @@ final class AccessibilityElement {
9898
}
9999
}
100100

101-
private func rawValue(for attribute: String) -> AnyObject? {
101+
private func rawValue(for attribute: NSAccessibilityAttributeName) -> AnyObject? {
102102
var rawValue: AnyObject?
103-
let error = AXUIElementCopyAttributeValue(self.elementRef, attribute as CFString, &rawValue)
103+
let error = AXUIElementCopyAttributeValue(self.elementRef, attribute.rawValue as CFString, &rawValue)
104104
return error == .success ? rawValue : nil
105105
}
106106

107-
private func value(for attribute: String) -> Self? {
107+
private func value(for attribute: NSAccessibilityAttributeName) -> Self? {
108108
if let rawValue = self.rawValue(for: attribute), CFGetTypeID(rawValue) == AXUIElementGetTypeID() {
109109
return type(of: self).init(elementRef: rawValue as! AXUIElement)
110110
}
111111

112112
return nil
113113
}
114114

115-
private func value(for attribute: String) -> String? {
115+
private func value(for attribute: NSAccessibilityAttributeName) -> String? {
116116
return self.rawValue(for: attribute) as? String
117117
}
118118

119-
private func value<T>(for attribute: String) -> T? {
119+
private func value<T>(for attribute: NSAccessibilityAttributeName) -> T? {
120120
if let rawValue = self.rawValue(for: attribute), CFGetTypeID(rawValue) == AXValueGetTypeID() {
121121
return (rawValue as! AXValue).toValue()
122122
}

ModMove/LoginAlert.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ struct LoginAlert {
1616
alert.addButton(withTitle: "Open at Login")
1717
alert.addButton(withTitle: "Cancel")
1818
let response = alert.runModal()
19-
if alert.suppressionButton?.state == NSOnState {
19+
if alert.suppressionButton?.state == .on {
2020
UserDefaults.standard.set(true, forKey: SuppressionKey)
2121
}
2222

23-
if response == NSAlertFirstButtonReturn {
23+
if response == .alertFirstButtonReturn {
2424
LoginController.setOpensAtLogin(true)
2525
}
2626
}

ModMove/Mover.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ final class Mover {
2424
return
2525
}
2626

27-
let currentPid = NSRunningApplication.current().processIdentifier
27+
let currentPid = NSRunningApplication.current.processIdentifier
2828
if let pid = window.pid(), pid != currentPid {
2929
NSRunningApplication(processIdentifier: pid)?.activate(options: .activateIgnoringOtherApps)
3030
}

ModMove/Observer.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ final class Observer {
1616
}
1717
}
1818

19-
private func state(for flags: NSEventModifierFlags) -> FlagState {
19+
private func state(for flags: NSEvent.ModifierFlags) -> FlagState {
2020
let hasMain = flags.contains(.control) && flags.contains(.option)
2121
let hasShift = flags.contains(.shift)
2222

0 commit comments

Comments
 (0)