Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ only_rules:
# Prefer `contains` over using `filter(where:).isEmpty`.
- contains_over_filter_is_empty

# Prefer `contains` over `first(where:) != nil`.
- contains_over_first_not_nil

# if,for,while,do statements shouldn't wrap their conditionals in parentheses.
- control_statement

Expand Down
2 changes: 1 addition & 1 deletion Sources/WordPressData/Swift/AbstractPost.swift
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ public extension AbstractPost {
/// Returns true if the post has any media that needs manual intervention to be uploaded
///
func hasPermanentFailedMedia() -> Bool {
return media.first(where: { !$0.willAttemptToUploadLater() }) != nil
return media.contains(where: { !$0.willAttemptToUploadLater() })
}

/// Returns all revisions of the post including the original one.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,6 @@ extension NSFetchedResultsController {
@objc public func isEmpty() -> Bool {
// We can not return fetchedObjects.count == 0 because of a Swift compiler error:
// Extension of a generic Objective-C class cannot access the class's generic parameters at runtime
return sections?.first(where: { $0.numberOfObjects > 0 }) == nil
return sections?.contains(where: { $0.numberOfObjects > 0 }) != true
}
}
4 changes: 2 additions & 2 deletions WordPress/Classes/Stores/StatsInsightsStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -936,7 +936,7 @@ extension StatsInsightsStore {
* with value .loading. If at least one exists then the store is still fetching the overview.
*/
let mirror = Mirror(reflecting: state)
return mirror.children.compactMap { $0.value as? StoreFetchingStatus }.first { $0 == .loading } != nil
return mirror.children.compactMap { $0.value as? StoreFetchingStatus }.contains { $0 == .loading }
}

var isFetchingAllFollowers: Bool {
Expand Down Expand Up @@ -996,7 +996,7 @@ extension StatsInsightsStore {
* If the result is nil the store failed loading the overview.
*/
let mirror = Mirror(reflecting: state)
return mirror.children.compactMap { $0.value as? StoreFetchingStatus }.first { $0 != .error } == nil
return !mirror.children.compactMap { $0.value as? StoreFetchingStatus }.contains { $0 != .error }
}

func fetchingFailed(for query: InsightQuery) -> Bool {
Expand Down
4 changes: 2 additions & 2 deletions WordPress/Classes/Stores/StatsPeriodStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1050,7 +1050,7 @@ private extension StatsPeriodStore {
state.topSearchTermsStatus,
state.topCountriesStatus,
state.topVideosStatus,
state.topFileDownloadsStatus].first { $0 == .loading } == nil
state.topFileDownloadsStatus].allSatisfy { $0 != .loading }
}

private func setAllFetchingStatus(_ status: StoreFetchingStatus) {
Expand Down Expand Up @@ -1263,7 +1263,7 @@ extension StatsPeriodStore {
state.topSearchTermsStatus,
state.topCountriesStatus,
state.topVideosStatus,
state.topFileDownloadsStatus].first { $0 != .error } == nil
state.topFileDownloadsStatus].allSatisfy { $0 == .error }
}

func fetchingFailed(for query: PeriodQuery) -> Bool {
Expand Down
6 changes: 3 additions & 3 deletions WordPress/Classes/Stores/StatsRevampStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,11 @@ extension StatsRevampStore {

private extension StatsRevampStore {
func aggregateStatus(for statuses: [StoreFetchingStatus], data: Any?) -> StoreFetchingStatus {
if statuses.first(where: { $0 == .loading }) != nil {
if statuses.contains(where: { $0 == .loading }) {
return .loading
} else if statuses.first(where: { $0 == .success }) != nil || data != nil {
} else if statuses.contains(where: { $0 == .success }) || data != nil {
return .success
} else if statuses.first(where: { $0 == .error }) != nil {
} else if statuses.contains(where: { $0 == .error }) {
return .error
} else {
return .idle
Expand Down
2 changes: 1 addition & 1 deletion WordPress/Classes/Stores/StatsStore+Cache.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ protocol StatsStoreCacheable {

extension StatsStoreCacheable {
func containsCachedData(for types: [StatsStoreType]) -> Bool {
return types.first { containsCachedData(for: $0) } != nil
return types.contains { containsCachedData(for: $0) }
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ private extension NotificationsViewController {
guard let notes = tableViewHandler?.resultsController?.fetchedObjects as? [WordPressData.Notification] else {
return nil
}
let isEnabled = notes.first { !$0.read } != nil
let isEnabled = notes.contains { !$0.read }
let attributes = isEnabled ? UIAction.Attributes(rawValue: 0) : .disabled
return UIAction(
title: Strings.NavigationBar.markAllAsReadActionTitle,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ private extension TabbedTotalsCell {

func toggleFilterTabBar() {
// If none of the tabs have data, hide the FilterTabBar.
let noTabsData = (tabsData.first { !$0.dataRows.isEmpty }) == nil
let noTabsData = !tabsData.contains { !$0.dataRows.isEmpty }
filterTabBar.isHidden = noTabsData
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ private extension SupportTableViewController {
///
func checkForAutomatticEmail() {
guard let email = ZendeskUtils.userSupportEmail(),
(ZendeskUtils.automatticEmails.first { email.contains($0) }) != nil else {
ZendeskUtils.automatticEmails.contains(where: { email.contains($0) }) else {
return
}

Expand Down