Replace uses of forEach with for-in loops.

This commit is contained in:
Brent Simmons
2023-07-09 22:14:09 -07:00
parent 090e63b017
commit abb11afe3d
6 changed files with 43 additions and 35 deletions

View File

@@ -777,7 +777,7 @@ private extension FeedbinAccountDelegate {
// Delete any folders not at Feedbin
if let folders = account.folders {
folders.forEach { folder in
for folder in folders {
if !tagNames.contains(folder.name ?? "") {
for feed in folder.topLevelFeeds {
account.addFeed(feed)
@@ -797,7 +797,7 @@ private extension FeedbinAccountDelegate {
}()
// Make any folders Feedbin has, but we don't
tagNames.forEach { tagName in
for tagName in tagNames {
if !folderNames.contains(tagName) {
_ = account.ensureFolder(with: tagName)
}
@@ -811,29 +811,29 @@ private extension FeedbinAccountDelegate {
assert(Thread.isMainThread)
logger.debug("Syncing feeds with \(subscriptions.count, privacy: .public) subscriptions.")
let subFeedIds = subscriptions.map { String($0.feedID) }
// Remove any feeds that are no longer in the subscriptions
if let folders = account.folders {
for folder in folders {
for feed in folder.topLevelFeeds {
if !subFeedIds.contains(feed.feedID) {
folder.removeFeed(feed)
}
}
}
}
for feed in account.topLevelFeeds {
if !subFeedIds.contains(feed.feedID) {
account.removeFeed(feed)
}
}
// Add any feeds we don't have and update any we do
var subscriptionsToAdd = Set<FeedbinSubscription>()
subscriptions.forEach { subscription in
let subFeedIds = subscriptions.map { String($0.feedID) }
// Remove any feeds that are no longer in the subscriptions
if let folders = account.folders {
for folder in folders {
for feed in folder.topLevelFeeds {
if !subFeedIds.contains(feed.feedID) {
folder.removeFeed(feed)
}
}
}
}
for feed in account.topLevelFeeds {
if !subFeedIds.contains(feed.feedID) {
account.removeFeed(feed)
}
}
// Add any feeds we don't have and update any we do
var subscriptionsToAdd = Set<FeedbinSubscription>()
for subscription in subscriptions {
let subFeedId = String(subscription.feedID)
@@ -852,7 +852,7 @@ private extension FeedbinAccountDelegate {
}
// Actually add subscriptions all in one go, so we dont trigger various rebuilding things that Account does.
subscriptionsToAdd.forEach { subscription in
for subscription in subscriptionsToAdd {
let feed = account.createFeed(with: subscription.name, url: subscription.url, feedID: String(subscription.feedID), homePageURL: subscription.homePageURL)
feed.externalID = String(subscription.subscriptionID)
account.addFeed(feed)

View File

@@ -62,7 +62,7 @@ import Account
private static func addFolderItemsToMenuWithNodes(menu: NSMenu, nodes: [Node], indentationLevel: Int) {
nodes.forEach { (oneNode) in
for oneNode in nodes {
if let nameProvider = oneNode.representedObject as? DisplayNameProvider {

View File

@@ -24,7 +24,9 @@ import Foundation
func cancelAllRequests() {
precondition(Thread.isMainThread)
pendingRequests.forEach { $0.isCanceled = true }
for pendingRequest in pendingRequests {
pendingRequest.isCanceled = true
}
currentRequest?.isCanceled = true
pendingRequests = [FetchRequestOperation]()
}

View File

@@ -879,9 +879,9 @@ private extension MasterFeedViewController {
}
func applyToAvailableCells(_ completion: (MasterFeedTableViewCell, IndexPath) -> Void) {
tableView.visibleCells.forEach { cell in
for cell in tableView.visibleCells {
guard let indexPath = tableView.indexPath(for: cell) else {
return
continue
}
completion(cell as! MasterFeedTableViewCell, indexPath)
}

View File

@@ -476,9 +476,12 @@ class MasterTimelineViewController: UITableViewController, UndoableCommandRunner
guard let feed = note.userInfo?[UserInfoKey.feed] as? Feed else {
return
}
tableView.indexPathsForVisibleRows?.forEach { indexPath in
guard let indexPathsForVisibleRows = tableView.indexPathsForVisibleRows else {
return
}
for indexPath in indexPathsForVisibleRows {
guard let article = dataSource.itemIdentifier(for: indexPath) else {
return
continue
}
if article.feed == feed, let cell = tableView.cellForRow(at: indexPath) as? MasterTimelineTableViewCell, let image = iconImageFor(article) {
cell.setIconImage(image)
@@ -490,9 +493,12 @@ class MasterTimelineViewController: UITableViewController, UndoableCommandRunner
guard coordinator.showIcons, let avatarURL = note.userInfo?[UserInfoKey.url] as? String else {
return
}
tableView.indexPathsForVisibleRows?.forEach { indexPath in
guard let indexPathsForVisibleRows = tableView.indexPathsForVisibleRows else {
return
}
for indexPath in indexPathsForVisibleRows {
guard let article = dataSource.itemIdentifier(for: indexPath), let authors = article.authors, !authors.isEmpty else {
return
continue
}
for author in authors {
if author.avatarURL == avatarURL, let cell = tableView.cellForRow(at: indexPath) as? MasterTimelineTableViewCell, let image = iconImageFor(article) {

View File

@@ -1468,7 +1468,7 @@ private extension SceneCoordinator {
func rebuildArticleDictionaries() {
var idDictionary = [String: Article]()
articles.forEach { article in
for article in articles {
idDictionary[article.articleID] = article
}