Skip to content
This repository has been archived by the owner on Mar 6, 2024. It is now read-only.

Commit

Permalink
Upgrade to Swift 5.1
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Sep 11, 2019
1 parent 0bd6ad7 commit 250284d
Show file tree
Hide file tree
Showing 9 changed files with 151 additions and 126 deletions.
28 changes: 25 additions & 3 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ whitelist_rules:
- comma
- compiler_protocol_init
- conditional_returns_on_newline
- contains_over_filter_count
- contains_over_filter_is_empty
- contains_over_first_not_nil
- control_statement
- deployment_target
Expand All @@ -21,8 +23,10 @@ whitelist_rules:
- discouraged_object_literal
- discouraged_optional_boolean
- discouraged_optional_collection
- duplicate_enum_cases
- duplicate_imports
- dynamic_inline
- empty_collection_literal
- empty_count
- empty_enum_arguments
- empty_parameters
Expand All @@ -48,6 +52,7 @@ whitelist_rules:
- legacy_constant
- legacy_constructor
- legacy_hashing
- legacy_multiple
- legacy_nsgeometry_functions
- legacy_random
- literal_expression_end_indentation
Expand All @@ -63,7 +68,9 @@ whitelist_rules:
- nimble_operator
- no_extension_access_modifier
- no_fallthrough_only
- no_space_in_method_call
- notification_center_detachment
- nsobject_prefer_isequal
- number_separator
- object_literal
- opening_brace
Expand All @@ -76,6 +83,8 @@ whitelist_rules:
- private_unit_test
- prohibited_super_call
- protocol_property_accessors_order
- reduce_boolean
- reduce_into
- redundant_discardable_let
- redundant_nil_coalescing
- redundant_objc_attribute
Expand All @@ -95,6 +104,7 @@ whitelist_rules:
- switch_case_alignment
- switch_case_on_newline
- syntactic_sugar
- todo
- toggle_bool
- trailing_closure
- trailing_comma
Expand All @@ -105,7 +115,9 @@ whitelist_rules:
- unavailable_function
- unneeded_break_in_switch
- unneeded_parentheses_in_closure_argument
- unowned_variable_capture
- untyped_error_in_catch
- unused_capture_list
- unused_closure_parameter
- unused_control_flow_label
- unused_enumerated
Expand All @@ -117,15 +129,13 @@ whitelist_rules:
- vertical_whitespace_closing_braces
- vertical_whitespace_opening_braces
- void_return
- weak_computed_property
- weak_delegate
- xct_specific_matcher
- xctfail_message
- yoda_condition
- todo
analyzer_rules:
- unused_declaration
- unused_import
- unused_private_declaration
force_cast: warning
force_unwrapping: warning
number_separator:
Expand All @@ -134,6 +144,18 @@ object_literal:
image_literal: false
discouraged_object_literal:
color_literal: false
type_contents_order:
order:
- case
- [type_alias, associated_type, subtype]
- type_property
- type_method
- ib_outlet
- [ib_inspectable, instance_property]
- initializer
- subscript
- view_life_cycle_method
- [ib_action, other_method]
identifier_name:
max_length:
warning: 100
Expand Down
2 changes: 1 addition & 1 deletion Cartfile.resolved
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
github "sindresorhus/Defaults" "v2.0.0"
github "sindresorhus/Defaults" "v3.0.0"
github "sparkle-project/Sparkle" "1.21.3"
15 changes: 10 additions & 5 deletions Touch Bar Simulator.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
archiveVersion = 1;
classes = {
};
objectVersion = 51;
objectVersion = 52;
objects = {

/* Begin PBXBuildFile section */
Expand Down Expand Up @@ -163,7 +163,7 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0820;
LastUpgradeCheck = 0930;
LastUpgradeCheck = 1100;
ORGANIZATIONNAME = "Sindre Sorhus";
TargetAttributes = {
E3FE2CBE1E726CE800C6713A = {
Expand All @@ -180,10 +180,11 @@
};
};
buildConfigurationList = E3FE2CBA1E726CE800C6713A /* Build configuration list for PBXProject "Touch Bar Simulator" */;
compatibilityVersion = "Xcode 10.0";
compatibilityVersion = "Xcode 11.0";
developmentRegion = en;
hasScannedForEncodings = 0;
knownRegions = (
en,
Base,
);
mainGroup = E3FE2CB61E726CE800C6713A;
Expand Down Expand Up @@ -296,13 +297,14 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
MACOSX_DEPLOYMENT_TARGET = 10.14;
MACOSX_DEPLOYMENT_TARGET = 10.14.4;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = macosx;
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
SWIFT_COMPILATION_MODE = singlefile;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 5.0;
VALID_ARCHS = x86_64;
};
name = Debug;
Expand Down Expand Up @@ -349,11 +351,12 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
MACOSX_DEPLOYMENT_TARGET = 10.14;
MACOSX_DEPLOYMENT_TARGET = 10.14.4;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = macosx;
SWIFT_COMPILATION_MODE = wholemodule;
SWIFT_OPTIMIZATION_LEVEL = "-O";
SWIFT_VERSION = 5.0;
VALID_ARCHS = x86_64;
};
name = Release;
Expand All @@ -366,6 +369,7 @@
CODE_SIGN_IDENTITY = "Mac Developer";
COMBINE_HIDPI_IMAGES = YES;
DEVELOPMENT_TEAM = YG56YK5RN5;
ENABLE_HARDENED_RUNTIME = YES;
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
"$(PROJECT_DIR)",
Expand Down Expand Up @@ -404,6 +408,7 @@
CODE_SIGN_IDENTITY = "Mac Developer";
COMBINE_HIDPI_IMAGES = YES;
DEVELOPMENT_TEAM = YG56YK5RN5;
ENABLE_HARDENED_RUNTIME = YES;
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
"$(PROJECT_DIR)",
Expand Down
10 changes: 6 additions & 4 deletions Touch Bar Simulator/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ import Defaults

final class AppDelegate: NSObject, NSApplicationDelegate {
lazy var window = with(TouchBarWindow()) {
$0.alphaValue = CGFloat(defaults[.windowTransparency])
$0.alphaValue = CGFloat(Defaults[.windowTransparency])
$0.setUp()
}

lazy var statusItem = with(NSStatusBar.system.statusItem(withLength: NSStatusItem.squareLength)) {
$0.menu = with(NSMenu()) { $0.delegate = self }
$0.menu = with(NSMenu()) {
$0.delegate = self
}
$0.button!.image = NSImage(named: "MenuBarIcon")
$0.button!.toolTip = "Right-click or option-click for menu"
}
Expand Down Expand Up @@ -95,7 +97,7 @@ extension AppDelegate: NSMenuDelegate {
}

private func statusItemShouldShowMenu() -> Bool {
return !NSApp.isLeftMouseDown || NSApp.isOptionKeyDown
!NSApp.isLeftMouseDown || NSApp.isOptionKeyDown
}

func menuNeedsUpdate(_ menu: NSMenu) {
Expand All @@ -111,7 +113,7 @@ extension AppDelegate: NSMenuDelegate {
private func statusItemButtonClicked() {
// When the user explicitly wants the Touch Bar to appear then `dockBahavior` should be disabled.
// This is also how the macOS Dock behaves.
defaults[.dockBehavior] = false
Defaults[.dockBehavior] = false

toggleView()

Expand Down
16 changes: 8 additions & 8 deletions Touch Bar Simulator/Glue.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import Defaults

extension Defaults {
@discardableResult
func observe<T: Codable, Weak: AnyObject>(
static func observe<T: Codable, Weak: AnyObject>(
_ key: Key<T>,
tiedToLifetimeOf weaklyHeldObject: Weak,
options: NSKeyValueObservingOptions = [.initial, .new, .old],
Expand Down Expand Up @@ -40,17 +40,17 @@ extension NSMenuItem {
*/
func bindState(to key: Defaults.Key<Bool>) -> Self {
addAction { _ in
defaults[key].toggle()
Defaults[key].toggle()
}

defaults.observe(key, tiedToLifetimeOf: self) { [unowned self] change in
Defaults.observe(key, tiedToLifetimeOf: self) { [unowned self] change in
self.isChecked = change.newValue
}

return self
}

// TODO: The doc comments here are out of date
// TODO: The doc comments here are out of date.
/**
Adds an action to this menu item that sets the value of `key` in the
defaults system to `value`, and initializes this item's state based on
Expand All @@ -66,10 +66,10 @@ extension NSMenuItem {
*/
func bindChecked<Value: Equatable>(to key: Defaults.Key<Value>, value: Value) -> Self {
addAction { _ in
defaults[key] = value
Defaults[key] = value
}

defaults.observe(key, tiedToLifetimeOf: self) { [unowned self] change in
Defaults.observe(key, tiedToLifetimeOf: self) { [unowned self] change in
self.isChecked = (change.newValue == value)
}

Expand All @@ -91,10 +91,10 @@ extension NSSlider {
*/
func bindDoubleValue(to key: Defaults.Key<Double>) -> Self {
addAction { sender in
defaults[key] = sender.doubleValue
Defaults[key] = sender.doubleValue
}

defaults.observe(key, tiedToLifetimeOf: self) { [unowned self] change in
Defaults.observe(key, tiedToLifetimeOf: self) { [unowned self] change in
self.doubleValue = change.newValue
}

Expand Down
8 changes: 4 additions & 4 deletions Touch Bar Simulator/ToolbarSlider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ private final class ToolbarSliderCell: NSSliderCell {
var frame = knobRect.insetBy(dx: 0, dy: 6.5)
if let shadow = self.shadow {
// Make room on either side of the view for the shadow to spill into,
// rather than clip on the edges
// rather than clip on the edges.
frame.origin.x *= ((barRect.width - shadow.shadowBlurRadius * 2) / barRect.width)
frame.origin.x += shadow.shadowBlurRadius
}

// Make the slider grey
// Make the slider grey.
var greySliderFrame = barRect
greySliderFrame.origin.x -= 1
greySliderFrame.origin.y = barRect.origin.y + 1
Expand All @@ -46,7 +46,7 @@ private final class ToolbarSliderCell: NSSliderCell {
fillColor.set()
path.fill()

// Border should not draw a shadow
// Border should not draw a shadow.
NSShadow().set()

// Border
Expand Down Expand Up @@ -81,7 +81,7 @@ extension NSSlider {
// itself brighter for some reason.
func alwaysRedisplayOnValueChanged() -> Self {
addAction { sender in
if (defaults[.windowTransparency] - sender.doubleValue) != 0 {
if (Defaults[.windowTransparency] - sender.doubleValue) != 0 {
sender.needsDisplay = true
}
}
Expand Down
6 changes: 2 additions & 4 deletions Touch Bar Simulator/TouchBarView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ final class TouchBarView: NSView {
stop()
}

override func acceptsFirstMouse(for event: NSEvent?) -> Bool {
return true
}
override func acceptsFirstMouse(for event: NSEvent?) -> Bool { true }

func start() {
stream = SLSDFRDisplayStreamCreate(0, .main) { status, _, frameSurface, _ in
Expand All @@ -38,7 +36,7 @@ final class TouchBarView: NSView {
}

func stop() {
guard let stream = stream else {
guard let stream = self.stream else {
return
}

Expand Down
Loading

0 comments on commit 250284d

Please sign in to comment.