Skip to content

Commit 0d77aa6

Browse files
committed
Upgrade to Swift 5.5
1 parent 32aef04 commit 0d77aa6

File tree

4 files changed

+27
-39
lines changed

4 files changed

+27
-39
lines changed

Example/KeyboardShortcutsExample.xcodeproj/project.pbxproj

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,17 @@
77
objects = {
88

99
/* Begin PBXBuildFile section */
10+
E33F1EFC26F3B89C00ACEB0F /* KeyboardShortcuts in Frameworks */ = {isa = PBXBuildFile; productRef = E33F1EFB26F3B89C00ACEB0F /* KeyboardShortcuts */; };
1011
E36FB94A2609BA43004272D9 /* App.swift in Sources */ = {isa = PBXBuildFile; fileRef = E36FB9492609BA43004272D9 /* App.swift */; };
1112
E36FB94C2609BA43004272D9 /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = E36FB94B2609BA43004272D9 /* ContentView.swift */; };
1213
E36FB94E2609BA45004272D9 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = E36FB94D2609BA45004272D9 /* Assets.xcassets */; };
1314
E36FB9512609BA45004272D9 /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = E36FB9502609BA45004272D9 /* Preview Assets.xcassets */; };
1415
E36FB9632609BB83004272D9 /* AppState.swift in Sources */ = {isa = PBXBuildFile; fileRef = E36FB9622609BB83004272D9 /* AppState.swift */; };
1516
E36FB9662609BF3D004272D9 /* Utilities.swift in Sources */ = {isa = PBXBuildFile; fileRef = E36FB9652609BF3D004272D9 /* Utilities.swift */; };
16-
E386C4D32609C0C500F147B8 /* KeyboardShortcuts in Frameworks */ = {isa = PBXBuildFile; productRef = E386C4D22609C0C500F147B8 /* KeyboardShortcuts */; };
1717
/* End PBXBuildFile section */
1818

1919
/* Begin PBXFileReference section */
20+
E33F1EFA26F3B78800ACEB0F /* KeyboardShortcuts */ = {isa = PBXFileReference; lastKnownFileType = folder; name = KeyboardShortcuts; path = ..; sourceTree = "<group>"; };
2021
E36FB9462609BA43004272D9 /* KeyboardShortcutsExample.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = KeyboardShortcutsExample.app; sourceTree = BUILT_PRODUCTS_DIR; };
2122
E36FB9492609BA43004272D9 /* App.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = App.swift; sourceTree = "<group>"; };
2223
E36FB94B2609BA43004272D9 /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = "<group>"; };
@@ -26,28 +27,34 @@
2627
E36FB9532609BA45004272D9 /* KeyboardShortcutsExample.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = KeyboardShortcutsExample.entitlements; sourceTree = "<group>"; };
2728
E36FB9622609BB83004272D9 /* AppState.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppState.swift; sourceTree = "<group>"; };
2829
E36FB9652609BF3D004272D9 /* Utilities.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Utilities.swift; sourceTree = "<group>"; };
29-
E386C4D02609C0B700F147B8 /* KeyboardShortcuts */ = {isa = PBXFileReference; lastKnownFileType = folder; name = KeyboardShortcuts; path = ..; sourceTree = "<group>"; };
3030
/* End PBXFileReference section */
3131

3232
/* Begin PBXFrameworksBuildPhase section */
3333
E36FB9432609BA43004272D9 /* Frameworks */ = {
3434
isa = PBXFrameworksBuildPhase;
3535
buildActionMask = 2147483647;
3636
files = (
37-
E386C4D32609C0C500F147B8 /* KeyboardShortcuts in Frameworks */,
37+
E33F1EFC26F3B89C00ACEB0F /* KeyboardShortcuts in Frameworks */,
3838
);
3939
runOnlyForDeploymentPostprocessing = 0;
4040
};
4141
/* End PBXFrameworksBuildPhase section */
4242

4343
/* Begin PBXGroup section */
44+
E33F1EF926F3B78800ACEB0F /* Packages */ = {
45+
isa = PBXGroup;
46+
children = (
47+
E33F1EFA26F3B78800ACEB0F /* KeyboardShortcuts */,
48+
);
49+
name = Packages;
50+
sourceTree = "<group>";
51+
};
4452
E36FB93D2609BA43004272D9 = {
4553
isa = PBXGroup;
4654
children = (
47-
E386C4D02609C0B700F147B8 /* KeyboardShortcuts */,
4855
E36FB9482609BA43004272D9 /* KeyboardShortcutsExample */,
4956
E36FB9472609BA43004272D9 /* Products */,
50-
E36FB95E2609BACA004272D9 /* Frameworks */,
57+
E33F1EF926F3B78800ACEB0F /* Packages */,
5158
);
5259
sourceTree = "<group>";
5360
};
@@ -82,13 +89,6 @@
8289
path = "Preview Content";
8390
sourceTree = "<group>";
8491
};
85-
E36FB95E2609BACA004272D9 /* Frameworks */ = {
86-
isa = PBXGroup;
87-
children = (
88-
);
89-
name = Frameworks;
90-
sourceTree = "<group>";
91-
};
9292
/* End PBXGroup section */
9393

9494
/* Begin PBXNativeTarget section */
@@ -106,7 +106,7 @@
106106
);
107107
name = KeyboardShortcutsExample;
108108
packageProductDependencies = (
109-
E386C4D22609C0C500F147B8 /* KeyboardShortcuts */,
109+
E33F1EFB26F3B89C00ACEB0F /* KeyboardShortcuts */,
110110
);
111111
productName = KeyboardShortcutsExample;
112112
productReference = E36FB9462609BA43004272D9 /* KeyboardShortcutsExample.app */;
@@ -222,7 +222,7 @@
222222
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
223223
GCC_WARN_UNUSED_FUNCTION = YES;
224224
GCC_WARN_UNUSED_VARIABLE = YES;
225-
MACOSX_DEPLOYMENT_TARGET = 11.1;
225+
MACOSX_DEPLOYMENT_TARGET = 11.3;
226226
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
227227
MTL_FAST_MATH = YES;
228228
ONLY_ACTIVE_ARCH = YES;
@@ -277,7 +277,7 @@
277277
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
278278
GCC_WARN_UNUSED_FUNCTION = YES;
279279
GCC_WARN_UNUSED_VARIABLE = YES;
280-
MACOSX_DEPLOYMENT_TARGET = 11.1;
280+
MACOSX_DEPLOYMENT_TARGET = 11.3;
281281
MTL_ENABLE_DEBUG_INFO = NO;
282282
MTL_FAST_MATH = YES;
283283
SDKROOT = macosx;
@@ -362,7 +362,7 @@
362362
/* End XCConfigurationList section */
363363

364364
/* Begin XCSwiftPackageProductDependency section */
365-
E386C4D22609C0C500F147B8 /* KeyboardShortcuts */ = {
365+
E33F1EFB26F3B89C00ACEB0F /* KeyboardShortcuts */ = {
366366
isa = XCSwiftPackageProductDependency;
367367
productName = KeyboardShortcuts;
368368
};

Example/KeyboardShortcutsExample/ContentView.swift

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,6 @@ extension KeyboardShortcuts.Name {
88
static let testShortcut4 = Self("testShortcut4")
99
}
1010

11-
// TODO: Replace this with `View#onChange` when macOS 11 is out.
12-
extension Binding {
13-
func onChange(_ handler: @escaping (Value, Value) -> Void) -> Binding<Value> {
14-
.init(
15-
get: {
16-
wrappedValue
17-
},
18-
set: {
19-
let oldValue = wrappedValue
20-
wrappedValue = $0
21-
handler(oldValue, wrappedValue)
22-
}
23-
)
24-
}
25-
}
26-
2711
private struct DynamicShortcutRecorder: View {
2812
@Binding var name: KeyboardShortcuts.Name
2913
@Binding var isPressed: Bool
@@ -49,7 +33,7 @@ private struct DynamicShortcut: View {
4933
Shortcut(id: "Shortcut4", name: .testShortcut4)
5034
]
5135

52-
@State private var shortcut = Self.shortcuts[0]
36+
@State private var shortcut = Self.shortcuts.first!
5337
@State private var isPressed = false
5438

5539
var body: some View {
@@ -58,9 +42,10 @@ private struct DynamicShortcut: View {
5842
.bold()
5943
.padding(.bottom, 10)
6044
VStack {
61-
Picker("Select shortcut:", selection: $shortcut.onChange(onShortcutChange)) {
45+
Picker("Select shortcut:", selection: $shortcut) {
6246
ForEach(Self.shortcuts) {
63-
Text($0.id).tag($0)
47+
Text($0.id)
48+
.tag($0)
6449
}
6550
}
6651
Divider()
@@ -70,6 +55,9 @@ private struct DynamicShortcut: View {
7055
.frame(maxWidth: 300)
7156
.padding()
7257
.padding(.bottom, 20)
58+
.onChange(of: shortcut) { [oldValue = shortcut] in
59+
onShortcutChange(oldValue: oldValue, newValue: $0)
60+
}
7361
}
7462

7563
private func onShortcutChange(oldValue: Shortcut, newValue: Shortcut) {

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// swift-tools-version:5.4
1+
// swift-tools-version:5.5
22
import PackageDescription
33

44
let package = Package(

Sources/KeyboardShortcuts/RecorderCocoa.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ extension KeyboardShortcuts {
5454
/// :nodoc:
5555
override public var intrinsicContentSize: CGSize {
5656
var size = super.intrinsicContentSize
57-
size.width = CGFloat(minimumWidth)
57+
size.width = minimumWidth
5858
return size
5959
}
6060

@@ -88,7 +88,7 @@ extension KeyboardShortcuts {
8888
self.translatesAutoresizingMaskIntoConstraints = false
8989
setContentHuggingPriority(.defaultHigh, for: .vertical)
9090
setContentHuggingPriority(.defaultHigh, for: .horizontal)
91-
widthAnchor.constraint(greaterThanOrEqualToConstant: CGFloat(minimumWidth)).isActive = true
91+
widthAnchor.constraint(greaterThanOrEqualToConstant: minimumWidth).isActive = true
9292

9393
// Hide the cancel button when not showing the shortcut so the placeholder text is properly centered. Must be last.
9494
self.cancelButton = (cell as? NSSearchFieldCell)?.cancelButtonCell
@@ -165,7 +165,7 @@ extension KeyboardShortcuts {
165165
}
166166

167167
let clickPoint = self.convert(event.locationInWindow, from: nil)
168-
let clickMargin: CGFloat = 3
168+
let clickMargin = 3.0
169169

170170
if
171171
event.type == .leftMouseUp || event.type == .rightMouseUp,

0 commit comments

Comments
 (0)