From ff19d6438d7ec329721b57bdd65612d3b97f0b3d Mon Sep 17 00:00:00 2001 From: BAHATTIN KOC Date: Sun, 1 Sep 2024 02:04:54 +0300 Subject: [PATCH] Simplify contains(where:) with Key Paths --- Sources/Private/CoreAnimation/Layers/ShapeItemLayer.swift | 2 +- Sources/Private/CoreAnimation/Layers/ShapeLayer.swift | 2 +- Tests/SnapshotTests.swift | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Sources/Private/CoreAnimation/Layers/ShapeItemLayer.swift b/Sources/Private/CoreAnimation/Layers/ShapeItemLayer.swift index 2b3412d67f..0a1df6248b 100644 --- a/Sources/Private/CoreAnimation/Layers/ShapeItemLayer.swift +++ b/Sources/Private/CoreAnimation/Layers/ShapeItemLayer.swift @@ -24,7 +24,7 @@ final class ShapeItemLayer: BaseAnimationLayer { "`ShapeItemLayer` must contain exactly one `ShapeItem` that draws a `GPPath`") try context.compatibilityAssert( - !otherItems.contains(where: { $0.item.drawsCGPath }), + !otherItems.contains(where: \.item.drawsCGPath), "`ShapeItemLayer` must contain exactly one `ShapeItem` that draws a `GPPath`") super.init() diff --git a/Sources/Private/CoreAnimation/Layers/ShapeLayer.swift b/Sources/Private/CoreAnimation/Layers/ShapeLayer.swift index 6a38808af9..c39c9785f1 100644 --- a/Sources/Private/CoreAnimation/Layers/ShapeLayer.swift +++ b/Sources/Private/CoreAnimation/Layers/ShapeLayer.swift @@ -259,7 +259,7 @@ extension CALayer { // but in practice can be any combination of items. The implementation expects all path-drawing // shape items to be managed by a `GroupLayer`, so if there's a top-level path item we // have to create a placeholder group. - if parentGroup == nil, otherItems.contains(where: { $0.item.drawsCGPath }) { + if parentGroup == nil, otherItems.contains(where: \.item.drawsCGPath) { groupItems = [Group(items: items.map { $0.item }, name: "")] otherItems = [] } diff --git a/Tests/SnapshotTests.swift b/Tests/SnapshotTests.swift index fa0c82929d..6893950f85 100644 --- a/Tests/SnapshotTests.swift +++ b/Tests/SnapshotTests.swift @@ -64,8 +64,8 @@ final class SnapshotTests: XCTestCase { animationName = animationName.replacingOccurrences(of: "-", with: "/") XCTAssert( - Samples.sampleAnimationURLs.contains(where: { $0.absoluteString.hasSuffix("\(animationName).json") }) - || Samples.sampleAnimationURLs.contains(where: { $0.absoluteString.hasSuffix("\(animationName).lottie") }), + Samples.sampleAnimationURLs.contains(where: \.absoluteString.hasSuffix("\(animationName).json")) + || Samples.sampleAnimationURLs.contains(where: \.absoluteString.hasSuffix("\(animationName).lottie")), "Snapshot \"\(snapshotURL.lastPathComponent)\" has no corresponding sample animation. Expecting \(animationName).json|.lottie") } }