From 0be38b4eb3d190eb706323c66bd3a13c181a5a7b Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Sun, 9 Jul 2023 22:33:46 -0700 Subject: [PATCH] Replace uses of forEach with for-in loops. --- .../CloudKit/CloudKitAccountZone.swift | 33 ++++++++++--------- .../CloudKitAccountZoneDelegate.swift | 8 ++--- .../Sidebar/SidebarViewController.swift | 4 ++- Shared/Tree/FeedTreeControllerDelegate.swift | 4 +-- 4 files changed, 27 insertions(+), 22 deletions(-) diff --git a/Account/Sources/Account/CloudKit/CloudKitAccountZone.swift b/Account/Sources/Account/CloudKit/CloudKitAccountZone.swift index c637511c2..6e0b0c3ff 100644 --- a/Account/Sources/Account/CloudKit/CloudKitAccountZone.swift +++ b/Account/Sources/Account/CloudKit/CloudKitAccountZone.swift @@ -68,21 +68,24 @@ final class CloudKitAccountZone: CloudKitZone { } } - for item in items { - if let feedSpecifier = item.feedSpecifier { - processFeed(feedSpecifier: feedSpecifier, containerExternalID: rootExternalID) - } else { - if let title = item.titleFromAttributes { - let containerRecord = newContainerCKRecord(name: title) - records.append(containerRecord) - item.children?.forEach { itemChild in - if let feedSpecifier = itemChild.feedSpecifier { - processFeed(feedSpecifier: feedSpecifier, containerExternalID: containerRecord.externalID) - } - } - } - } - } + for item in items { + if let feedSpecifier = item.feedSpecifier { + processFeed(feedSpecifier: feedSpecifier, containerExternalID: rootExternalID) + } else { + if let title = item.titleFromAttributes { + let containerRecord = newContainerCKRecord(name: title) + records.append(containerRecord) + + if let itemChildren = item.children { + for itemChild in itemChildren { + if let feedSpecifier = itemChild.feedSpecifier { + processFeed(feedSpecifier: feedSpecifier, containerExternalID: containerRecord.externalID) + } + } + } + } + } + } save(records, completion: completion) } diff --git a/Account/Sources/Account/CloudKit/CloudKitAccountZoneDelegate.swift b/Account/Sources/Account/CloudKit/CloudKitAccountZoneDelegate.swift index 0ba754ad5..47d97d904 100644 --- a/Account/Sources/Account/CloudKit/CloudKitAccountZoneDelegate.swift +++ b/Account/Sources/Account/CloudKit/CloudKitAccountZoneDelegate.swift @@ -84,10 +84,10 @@ class CloudKitAcountZoneDelegate: CloudKitZoneDelegate { @MainActor func removeFeed(_ externalID: String) { if let feed = account?.existingFeed(withExternalID: externalID), let containers = account?.existingContainers(withFeed: feed) { - containers.forEach { - feed.dropConditionalGetInfo() - $0.removeFeed(feed) - } + for container in containers { + feed.dropConditionalGetInfo() + container.removeFeed(feed) + } } } diff --git a/Mac/MainWindow/Sidebar/SidebarViewController.swift b/Mac/MainWindow/Sidebar/SidebarViewController.swift index fbd38b367..a859e374e 100644 --- a/Mac/MainWindow/Sidebar/SidebarViewController.swift +++ b/Mac/MainWindow/Sidebar/SidebarViewController.swift @@ -115,7 +115,9 @@ protocol SidebarDelegate: AnyObject { } let selectedItemIdentifers = Set(selectedFeedsState.compactMap( { ItemIdentifier(userInfo: $0) })) - selectedItemIdentifers.forEach { treeControllerDelegate.addFilterException($0) } + for selectedItemIdentifier in selectedItemIdentifers { + treeControllerDelegate.addFilterException(selectedItemIdentifier) + } rebuildTreeAndReloadDataIfNeeded() diff --git a/Shared/Tree/FeedTreeControllerDelegate.swift b/Shared/Tree/FeedTreeControllerDelegate.swift index 523892385..b165d6142 100644 --- a/Shared/Tree/FeedTreeControllerDelegate.swift +++ b/Shared/Tree/FeedTreeControllerDelegate.swift @@ -82,12 +82,12 @@ private extension FeedTreeControllerDelegate { var updatedChildNodes = [Node]() - children.forEach { (representedObject) in + for representedObject in children { if let existingNode = containerNode.childNodeRepresentingObject(representedObject) { if !updatedChildNodes.contains(existingNode) { updatedChildNodes += [existingNode] - return + continue } }