You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+15Lines changed: 15 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3809,6 +3809,21 @@ _You can enable the following settings in Xcode by running [this script](resourc
3809
3809
```
3810
3810
</details>
3811
3811
3812
+
*<a id='count-where'></a>(<a href='#count-where'>link</a>) **Prefer using `count(where: { … })` over `filter { … }.count`**.
3813
+
3814
+
<details>
3815
+
3816
+
Swift 6.0 ([finally!](https://forums.swift.org/t/accepted-again-se-0220-count-where/66659)) added a `count(where:)` method to the standard library. Prefer using the `count(where:)` method over using the `filter(_:)` method followed by a `count` call.
3817
+
3818
+
```swift
3819
+
// WRONG
3820
+
let planetsWithMoons = planets.filter { !$0.moons.isEmpty }.count
3821
+
3822
+
// RIGHT
3823
+
let planetsWithMoons = planets.count(where: { !$0.moons.isEmpty })
0 commit comments