Remove a number of uses of forEach.

This commit is contained in:
Brent Simmons
2024-11-17 22:08:44 -08:00
parent 16d8b0066e
commit c1c4c8b1b6
14 changed files with 45 additions and 32 deletions

View File

@@ -705,9 +705,11 @@ extension AppDelegate {
}
@IBAction func debugDropConditionalGetInfo(_ sender: Any?) {
#if DEBUG
AccountManager.shared.activeAccounts.forEach{ $0.debugDropConditionalGetInfo() }
#endif
#if DEBUG
for account in AccountManager.shared.activeAccounts {
account.debugDropConditionalGetInfo()
}
#endif
}
@IBAction func debugTestCrashReporterWindow(_ sender: Any?) {

View File

@@ -62,8 +62,8 @@ class FolderTreeMenu {
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 {
let menuItem = NSMenuItem(title: nameProvider.nameForDisplay, action: nil, keyEquivalent: "")

View File

@@ -375,7 +375,7 @@ private extension SidebarOutlineDataSource {
return false
}
draggedNodes.forEach { node in
for node in draggedNodes {
if sameAccount(node, parentNode) {
if NSApplication.shared.currentEvent?.modifierFlags.contains(.option) ?? false {
copyFeedInAccount(node: node, to: parentNode)
@@ -464,7 +464,7 @@ private extension SidebarOutlineDataSource {
return false
}
draggedNodes.forEach { node in
for node in draggedNodes {
if !sameAccount(node, parentNode) {
copyFolderBetweenAccounts(node: node, to: parentNode)
}

View File

@@ -112,8 +112,10 @@ protocol SidebarDelegate: AnyObject {
}
let selectedFeedIdentifers = Set(selectedFeedsState.compactMap( { SidebarItemIdentifier(userInfo: $0) }))
selectedFeedIdentifers.forEach { treeControllerDelegate.addFilterException($0) }
for feedIdentifier in selectedFeedIdentifers {
treeControllerDelegate.addFilterException(feedIdentifier)
}
rebuildTreeAndReloadDataIfNeeded()
var selectIndexes = IndexSet()
@@ -529,7 +531,9 @@ private extension SidebarViewController {
}
func addAllSelectedToFilterExceptions() {
selectedFeeds.forEach { addToFilterExeptionsIfNecessary($0) }
for feed in selectedFeeds {
addToFilterExeptionsIfNecessary(feed)
}
}
func addToFilterExeptionsIfNecessary(_ feed: SidebarItem?) {
@@ -572,13 +576,12 @@ private extension SidebarViewController {
restoreSelection(to: savedSelection, sendNotificationIfChanged: true)
// Automatically expand any new or newly active accounts
AccountManager.shared.activeAccounts.forEach { account in
for account in AccountManager.shared.activeAccounts {
if !savedAccounts.contains(account) {
let accountNode = treeController.nodeInTreeRepresentingObject(account)
outlineView.expandItem(accountNode)
}
}
}
func rebuildTreeAndReloadDataIfNeeded() {

View File

@@ -231,7 +231,9 @@ private extension Array where Element == NSRect {
func maxY() -> CGFloat {
var y: CGFloat = 0.0
self.forEach { y = Swift.max(y, $0.maxY) }
for oneRect in self {
y = Swift.max(y, oneRect.maxY)
}
return y
}
}

View File

@@ -208,7 +208,7 @@ private extension TimelineViewController {
}
let menu = NSMenu(title: NSLocalizedString("Share", comment: "Share menu name"))
services.forEach { (service) in
for service in services {
service.delegate = sharingServiceDelegate
let menuItem = NSMenuItem(title: service.menuItemTitle, action: #selector(performShareServiceFromContextualMenu(_:)), keyEquivalent: "")
menuItem.image = service.image

View File

@@ -1045,7 +1045,7 @@ private extension TimelineViewController {
func updateArticleRowMap() {
var rowMap = [String: [Int]]()
var index = 0
articles.forEach { (article) in
for article in articles {
if var indexes = rowMap[article.articleID] {
indexes.append(index)
rowMap[article.articleID] = indexes
@@ -1066,9 +1066,9 @@ private extension TimelineViewController {
func indexesForArticleIDs(_ articleIDs: Set<String>) -> IndexSet {
var indexes = IndexSet()
articleIDs.forEach { (articleID) in
for articleID in articleIDs {
guard let rowsIndex = rows(for: articleID) else {
return
continue
}
for rowIndex in rowsIndex {
indexes.insert(rowIndex)

View File

@@ -48,9 +48,9 @@ final class DeleteCommand: UndoableCommand {
func perform() {
let group = DispatchGroup()
itemSpecifiers.forEach {
for itemSpecifier in itemSpecifiers {
group.enter()
$0.delete() {
itemSpecifier.delete() {
group.leave()
}
}
@@ -59,11 +59,12 @@ final class DeleteCommand: UndoableCommand {
self.treeController?.rebuild()
self.registerUndo()
}
}
func undo() {
itemSpecifiers.forEach { $0.restore() }
for itemSpecifier in itemSpecifiers {
itemSpecifier.restore()
}
registerRedo()
}

View File

@@ -127,7 +127,11 @@ private extension ExtensionFeedAddRequestFile {
os_log(.error, log: Self.log, "Save to disk coordination failed: %@.", error.localizedDescription)
}
requests?.forEach { processRequest($0) }
if let requests {
for request in requests {
processRequest(request)
}
}
}
func processRequest(_ request: ExtensionFeedAddRequest) {

View File

@@ -802,9 +802,9 @@ private extension FeedViewController {
}
func applyToAvailableCells(_ completion: (FeedTableViewCell, 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! FeedTableViewCell, indexPath)
}

View File

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

View File

@@ -452,9 +452,9 @@ class TimelineViewController: UITableViewController, UndoableCommandRunner {
guard let feed = note.userInfo?[UserInfoKey.feed] as? Feed else {
return
}
tableView.indexPathsForVisibleRows?.forEach { indexPath in
for indexPath in tableView.indexPathsForVisibleRows? {
guard let article = dataSource.itemIdentifier(for: indexPath) else {
return
continue
}
if article.feed == feed, let cell = tableView.cellForRow(at: indexPath) as? TimelineTableViewCell, let image = iconImageFor(article) {
cell.setIconImage(image)
@@ -466,9 +466,9 @@ class TimelineViewController: UITableViewController, UndoableCommandRunner {
guard coordinator.showIcons, let avatarURL = note.userInfo?[UserInfoKey.url] as? String else {
return
}
tableView.indexPathsForVisibleRows?.forEach { indexPath in
for indexPath in tableView.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? TimelineTableViewCell, let image = iconImageFor(article) {

View File

@@ -13,7 +13,9 @@ extension Array where Element == CGRect {
func maxY() -> CGFloat {
var y: CGFloat = 0.0
self.forEach { y = Swift.max(y, $0.maxY) }
for oneRect in self {
y = Swift.max(y, oneRect.maxY)
}
return y
}

View File

@@ -12,10 +12,9 @@ class RoundedProgressView: UIProgressView {
override func layoutSubviews() {
super.layoutSubviews()
subviews.forEach { subview in
for subview in subviews {
subview.layer.masksToBounds = true
subview.layer.cornerRadius = bounds.height / 2.0
}
}
}