Skip to content

Commit

Permalink
Upgrade to Swift 5.5
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Oct 3, 2021
1 parent 32aef04 commit 0d77aa6
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 39 deletions.
32 changes: 16 additions & 16 deletions Example/KeyboardShortcutsExample.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,17 @@
objects = {

/* Begin PBXBuildFile section */
E33F1EFC26F3B89C00ACEB0F /* KeyboardShortcuts in Frameworks */ = {isa = PBXBuildFile; productRef = E33F1EFB26F3B89C00ACEB0F /* KeyboardShortcuts */; };
E36FB94A2609BA43004272D9 /* App.swift in Sources */ = {isa = PBXBuildFile; fileRef = E36FB9492609BA43004272D9 /* App.swift */; };
E36FB94C2609BA43004272D9 /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = E36FB94B2609BA43004272D9 /* ContentView.swift */; };
E36FB94E2609BA45004272D9 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = E36FB94D2609BA45004272D9 /* Assets.xcassets */; };
E36FB9512609BA45004272D9 /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = E36FB9502609BA45004272D9 /* Preview Assets.xcassets */; };
E36FB9632609BB83004272D9 /* AppState.swift in Sources */ = {isa = PBXBuildFile; fileRef = E36FB9622609BB83004272D9 /* AppState.swift */; };
E36FB9662609BF3D004272D9 /* Utilities.swift in Sources */ = {isa = PBXBuildFile; fileRef = E36FB9652609BF3D004272D9 /* Utilities.swift */; };
E386C4D32609C0C500F147B8 /* KeyboardShortcuts in Frameworks */ = {isa = PBXBuildFile; productRef = E386C4D22609C0C500F147B8 /* KeyboardShortcuts */; };
/* End PBXBuildFile section */

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

/* Begin PBXFrameworksBuildPhase section */
E36FB9432609BA43004272D9 /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
E386C4D32609C0C500F147B8 /* KeyboardShortcuts in Frameworks */,
E33F1EFC26F3B89C00ACEB0F /* KeyboardShortcuts in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXFrameworksBuildPhase section */

/* Begin PBXGroup section */
E33F1EF926F3B78800ACEB0F /* Packages */ = {
isa = PBXGroup;
children = (
E33F1EFA26F3B78800ACEB0F /* KeyboardShortcuts */,
);
name = Packages;
sourceTree = "<group>";
};
E36FB93D2609BA43004272D9 = {
isa = PBXGroup;
children = (
E386C4D02609C0B700F147B8 /* KeyboardShortcuts */,
E36FB9482609BA43004272D9 /* KeyboardShortcutsExample */,
E36FB9472609BA43004272D9 /* Products */,
E36FB95E2609BACA004272D9 /* Frameworks */,
E33F1EF926F3B78800ACEB0F /* Packages */,
);
sourceTree = "<group>";
};
Expand Down Expand Up @@ -82,13 +89,6 @@
path = "Preview Content";
sourceTree = "<group>";
};
E36FB95E2609BACA004272D9 /* Frameworks */ = {
isa = PBXGroup;
children = (
);
name = Frameworks;
sourceTree = "<group>";
};
/* End PBXGroup section */

/* Begin PBXNativeTarget section */
Expand All @@ -106,7 +106,7 @@
);
name = KeyboardShortcutsExample;
packageProductDependencies = (
E386C4D22609C0C500F147B8 /* KeyboardShortcuts */,
E33F1EFB26F3B89C00ACEB0F /* KeyboardShortcuts */,
);
productName = KeyboardShortcutsExample;
productReference = E36FB9462609BA43004272D9 /* KeyboardShortcutsExample.app */;
Expand Down Expand Up @@ -222,7 +222,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
MACOSX_DEPLOYMENT_TARGET = 11.1;
MACOSX_DEPLOYMENT_TARGET = 11.3;
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
MTL_FAST_MATH = YES;
ONLY_ACTIVE_ARCH = YES;
Expand Down Expand Up @@ -277,7 +277,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
MACOSX_DEPLOYMENT_TARGET = 11.1;
MACOSX_DEPLOYMENT_TARGET = 11.3;
MTL_ENABLE_DEBUG_INFO = NO;
MTL_FAST_MATH = YES;
SDKROOT = macosx;
Expand Down Expand Up @@ -362,7 +362,7 @@
/* End XCConfigurationList section */

/* Begin XCSwiftPackageProductDependency section */
E386C4D22609C0C500F147B8 /* KeyboardShortcuts */ = {
E33F1EFB26F3B89C00ACEB0F /* KeyboardShortcuts */ = {
isa = XCSwiftPackageProductDependency;
productName = KeyboardShortcuts;
};
Expand Down
26 changes: 7 additions & 19 deletions Example/KeyboardShortcutsExample/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,6 @@ extension KeyboardShortcuts.Name {
static let testShortcut4 = Self("testShortcut4")
}

// TODO: Replace this with `View#onChange` when macOS 11 is out.
extension Binding {
func onChange(_ handler: @escaping (Value, Value) -> Void) -> Binding<Value> {
.init(
get: {
wrappedValue
},
set: {
let oldValue = wrappedValue
wrappedValue = $0
handler(oldValue, wrappedValue)
}
)
}
}

private struct DynamicShortcutRecorder: View {
@Binding var name: KeyboardShortcuts.Name
@Binding var isPressed: Bool
Expand All @@ -49,7 +33,7 @@ private struct DynamicShortcut: View {
Shortcut(id: "Shortcut4", name: .testShortcut4)
]

@State private var shortcut = Self.shortcuts[0]
@State private var shortcut = Self.shortcuts.first!
@State private var isPressed = false

var body: some View {
Expand All @@ -58,9 +42,10 @@ private struct DynamicShortcut: View {
.bold()
.padding(.bottom, 10)
VStack {
Picker("Select shortcut:", selection: $shortcut.onChange(onShortcutChange)) {
Picker("Select shortcut:", selection: $shortcut) {
ForEach(Self.shortcuts) {
Text($0.id).tag($0)
Text($0.id)
.tag($0)
}
}
Divider()
Expand All @@ -70,6 +55,9 @@ private struct DynamicShortcut: View {
.frame(maxWidth: 300)
.padding()
.padding(.bottom, 20)
.onChange(of: shortcut) { [oldValue = shortcut] in
onShortcutChange(oldValue: oldValue, newValue: $0)
}
}

private func onShortcutChange(oldValue: Shortcut, newValue: Shortcut) {
Expand Down
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version:5.4
// swift-tools-version:5.5
import PackageDescription

let package = Package(
Expand Down
6 changes: 3 additions & 3 deletions Sources/KeyboardShortcuts/RecorderCocoa.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ extension KeyboardShortcuts {
/// :nodoc:
override public var intrinsicContentSize: CGSize {
var size = super.intrinsicContentSize
size.width = CGFloat(minimumWidth)
size.width = minimumWidth
return size
}

Expand Down Expand Up @@ -88,7 +88,7 @@ extension KeyboardShortcuts {
self.translatesAutoresizingMaskIntoConstraints = false
setContentHuggingPriority(.defaultHigh, for: .vertical)
setContentHuggingPriority(.defaultHigh, for: .horizontal)
widthAnchor.constraint(greaterThanOrEqualToConstant: CGFloat(minimumWidth)).isActive = true
widthAnchor.constraint(greaterThanOrEqualToConstant: minimumWidth).isActive = true

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

let clickPoint = self.convert(event.locationInWindow, from: nil)
let clickMargin: CGFloat = 3
let clickMargin = 3.0

if
event.type == .leftMouseUp || event.type == .rightMouseUp,
Expand Down

0 comments on commit 0d77aa6

Please sign in to comment.