Skip to content

Commit b082153

Browse files
committed
Minor tweaks
1 parent ebaa6c0 commit b082153

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

.swiftlint.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ whitelist_rules:
7777
- operator_usage_whitespace
7878
- operator_whitespace
7979
- overridden_super_call
80-
- pattern_matching_keywords
8180
- private_action
8281
- private_outlet
8382
- private_unit_test

Sources/CircularProgress/Vendored/CustomButton+Util.swift

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,7 @@ final class AnimationDelegate: NSObject, CAAnimationDelegate {
7878
protocol LayerColorAnimation: AnyObject {}
7979
extension LayerColorAnimation where Self: CALayer {
8080
func animate(_ keyPath: ReferenceWritableKeyPath<Self, CGColor?>, to color: CGColor, duration: Double) {
81-
let keyPathString = NSExpression(forKeyPath: keyPath).keyPath
82-
let animation = CABasicAnimation(keyPath: keyPathString)
81+
let animation = CABasicAnimation(keyPath: keyPath.toString)
8382
animation.fromValue = self[keyPath: keyPath]
8483
animation.toValue = color
8584
animation.duration = duration
@@ -96,11 +95,10 @@ extension LayerColorAnimation where Self: CALayer {
9695
}
9796

9897
func add(_ animation: CAAnimation, forKeyPath keyPath: ReferenceWritableKeyPath<Self, CGColor?>, completion: @escaping ((Bool) -> Void)) {
99-
let keyPathString = NSExpression(forKeyPath: keyPath).keyPath
10098
let animationDelegate = AnimationDelegate()
10199
animationDelegate.didStopHandler = completion
102100
animation.delegate = animationDelegate
103-
add(animation, forKey: keyPathString)
101+
add(animation, forKey: keyPath.toString)
104102
}
105103
}
106104

Sources/CircularProgress/util.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import Cocoa
22

3+
34
/**
45
Convenience function for initializing an object and modifying its properties.
56

@@ -18,6 +19,7 @@ func with<T>(_ item: T, update: (inout T) throws -> Void) rethrows -> T {
1819
return this
1920
}
2021

22+
2123
extension NSColor {
2224
/// macOS 10.14 polyfill
2325
static let controlAccentColorPolyfill: NSColor = {
@@ -443,3 +445,11 @@ func assertMainThread(
443445
) {
444446
assert(Thread.isMainThread, "\(function) in \((file as NSString).lastPathComponent):\(line) must run on the main thread!")
445447
}
448+
449+
450+
extension KeyPath where Root: NSObject {
451+
/// Get the string version of the key path when the root is an `NSObject`.
452+
var toString: String {
453+
NSExpression(forKeyPath: self).keyPath
454+
}
455+
}

0 commit comments

Comments
 (0)