Skip to content

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 e7cb0fd commit 9e84f3a
Show file tree
Hide file tree
Showing 14 changed files with 98 additions and 96 deletions.
26 changes: 24 additions & 2 deletions .swiftlint.yml
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 Down Expand Up @@ -106,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 @@ -118,14 +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
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
7 changes: 7 additions & 0 deletions .swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions CircularProgress.xcodeproj/project.pbxproj
Expand Up @@ -187,7 +187,7 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0940;
LastUpgradeCheck = 0940;
LastUpgradeCheck = 1100;
TargetAttributes = {
"CircularProgress::CircularProgress" = {
LastSwiftMigration = 1020;
Expand Down Expand Up @@ -318,7 +318,7 @@
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
CODE_SIGN_IDENTITY = "";
CODE_SIGN_IDENTITY = "-";
CODE_SIGN_STYLE = Manual;
COMBINE_HIDPI_IMAGES = YES;
DEVELOPMENT_TEAM = "";
Expand Down Expand Up @@ -359,7 +359,7 @@
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
CODE_SIGN_IDENTITY = "";
CODE_SIGN_IDENTITY = "-";
CODE_SIGN_STYLE = Manual;
COMBINE_HIDPI_IMAGES = YES;
COPY_PHASE_STRIP = NO;
Expand Down Expand Up @@ -493,6 +493,7 @@
SUPPORTED_PLATFORMS = macosx;
SWIFT_ACTIVE_COMPILATION_CONDITIONS = SWIFT_PACKAGE;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 5.0;
USE_HEADERMAP = NO;
VALID_ARCHS = x86_64;
};
Expand Down Expand Up @@ -540,6 +541,7 @@
SWIFT_ACTIVE_COMPILATION_CONDITIONS = SWIFT_PACKAGE;
SWIFT_COMPILATION_MODE = wholemodule;
SWIFT_OPTIMIZATION_LEVEL = "-O";
SWIFT_VERSION = 5.0;
USE_HEADERMAP = NO;
VALID_ARCHS = x86_64;
};
Expand Down
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0940"
LastUpgradeVersion = "1100"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down Expand Up @@ -29,8 +29,6 @@
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
</Testables>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
Expand All @@ -51,8 +49,6 @@
ReferencedContainer = "container:CircularProgress.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
Expand Down
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1010"
LastUpgradeVersion = "1100"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand All @@ -27,8 +27,6 @@
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
</Testables>
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
Expand All @@ -38,8 +36,8 @@
ReferencedContainer = "container:CircularProgress.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
<Testables>
</Testables>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
Expand All @@ -61,8 +59,6 @@
ReferencedContainer = "container:CircularProgress.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
Expand Down
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1010"
LastUpgradeVersion = "1100"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down Expand Up @@ -29,8 +29,6 @@
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
</Testables>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
Expand All @@ -51,8 +49,6 @@
ReferencedContainer = "container:CircularProgress.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
Expand Down
2 changes: 1 addition & 1 deletion CircularProgressMac.podspec
Expand Up @@ -8,6 +8,6 @@ Pod::Spec.new do |s|
s.authors = { 'Sindre Sorhus' => 'sindresorhus@gmail.com' }
s.source = { :git => 'https://github.com/sindresorhus/CircularProgress.git', :tag => "v#{s.version}" }
s.source_files = 'Sources/**/*.swift'
s.swift_version = '5'
s.swift_version = '5.1'
s.platform = :macos, '10.12'
end
4 changes: 1 addition & 3 deletions Example/AppDelegate.swift
Expand Up @@ -19,9 +19,7 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
configureProgressBasedView()
}

func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool {
return true
}
func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool { true }

private func configureManualView() {
animateWithRandomColor(
Expand Down
13 changes: 6 additions & 7 deletions Example/util.swift
Expand Up @@ -56,18 +56,17 @@ extension NSColor {
]

private static let uniqueRandomSystemColors = systemColors.uniqueRandomElementIterator()
static func uniqueRandomSystemColor() -> NSColor {
return uniqueRandomSystemColors.next()!
}

static func uniqueRandomSystemColor() -> NSColor { uniqueRandomSystemColors.next()! }
}


extension CGRect {
/**
Returns a CGRect where `self` is centered in `rect`
Returns a CGRect where `self` is centered in `rect`.
*/
func centered(in rect: CGRect, xOffset: Double = 0, yOffset: Double = 0) -> CGRect {
return CGRect(
func centered(in rect: Self, xOffset: Double = 0, yOffset: Double = 0) -> Self {
Self(
x: ((rect.width - size.width) / 2) + CGFloat(xOffset),
y: ((rect.height - size.height) / 2) + CGFloat(yOffset),
width: size.width,
Expand All @@ -79,7 +78,7 @@ extension CGRect {

extension NSView {
/**
- Note: You should almost never need to set `appearanceName` as it's done automatically
- Note: You should almost never need to set `appearanceName` as it's done automatically.
*/
@discardableResult
func insertVibrancyView(
Expand Down
2 changes: 1 addition & 1 deletion Package.swift
@@ -1,4 +1,4 @@
// swift-tools-version:5.0
// swift-tools-version:5.1
import PackageDescription

let package = Package(
Expand Down
19 changes: 6 additions & 13 deletions Sources/CircularProgress/CircularProgress.swift
Expand Up @@ -37,7 +37,7 @@ public final class CircularProgress: NSView {

private lazy var cancelButton = with(CustomButton.circularButton(title: "", radius: Double(radius), center: bounds.center)) {
$0.textColor = color
$0.backgroundColor = color.with(alpha: 0.1)
$0.backgroundColor = color.withAlpha(0.1)
$0.activeBackgroundColor = color
$0.borderWidth = 0
$0.isHidden = true
Expand All @@ -60,13 +60,10 @@ public final class CircularProgress: NSView {
Defaults to the user's accent color. For High Sierra and below it uses a fallback color.
*/
@IBInspectable public var color: NSColor {
get {
return _color
}
get { _color }
set {
_color = newValue
originalColor = newValue

needsDisplay = true
}
}
Expand All @@ -83,9 +80,7 @@ public final class CircularProgress: NSView {
- Note: Can be set from a background thread.
*/
@IBInspectable public var progress: Double {
get {
return _progress
}
get { _progress }
set {
_progress = newValue.clamped(to: 0...1)

Expand Down Expand Up @@ -208,15 +203,15 @@ public final class CircularProgress: NSView {

private func updateColors() {
let duration = 0.2
backgroundCircle.animate(color: color.with(alpha: 0.5).cgColor, keyPath: #keyPath(CAShapeLayer.strokeColor), duration: duration)
backgroundCircle.animate(color: color.withAlpha(0.5).cgColor, keyPath: #keyPath(CAShapeLayer.strokeColor), duration: duration)

progressCircle.animate(color: color.cgColor, keyPath: #keyPath(CAShapeLayer.strokeColor), duration: duration)
progressLabel.animate(color: color.cgColor, keyPath: #keyPath(CATextLayer.foregroundColor), duration: duration)

indeterminateCircle.animate(color: color.cgColor, keyPath: #keyPath(CAShapeLayer.strokeColor), duration: duration)

cancelButton.textColor = color
cancelButton.backgroundColor = color.with(alpha: 0.1)
cancelButton.backgroundColor = color.withAlpha(0.1)
cancelButton.activeBackgroundColor = color

successView.color = color
Expand Down Expand Up @@ -418,18 +413,16 @@ public final class CircularProgress: NSView {
private func startIndeterminateState() {
progressCircle.isHidden = true
indeterminateCircle.isHidden = false

progressLabel.isHidden = progress == 0 && isIndeterminate && cancelButton.isHidden
}

private func stopIndeterminateState() {
indeterminateCircle.isHidden = true
progressCircle.isHidden = false

progressLabel.isHidden = !cancelButton.isHidden
}

private var shouldHideSuccessView: Bool {
return !showCheckmarkAtHundredPercent || !isFinished || isCancelled
!showCheckmarkAtHundredPercent || !isFinished || isCancelled
}
}

0 comments on commit 9e84f3a

Please sign in to comment.