From 207ca04a0f7f6cc9ea848001af7abd099304e2f7 Mon Sep 17 00:00:00 2001 From: Insu Byeon Date: Tue, 6 Apr 2021 17:10:22 +0900 Subject: [PATCH] Use forEach instead of map method If you don't use a return value, using forEach method is better than the map method. --- .../Sample/MosaicCollectionViewLayout.swift | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/examples/CustomCollectionView-Swift/Sample/MosaicCollectionViewLayout.swift b/examples/CustomCollectionView-Swift/Sample/MosaicCollectionViewLayout.swift index 3d5a80d8a..a535ff8ff 100644 --- a/examples/CustomCollectionView-Swift/Sample/MosaicCollectionViewLayout.swift +++ b/examples/CustomCollectionView-Swift/Sample/MosaicCollectionViewLayout.swift @@ -81,7 +81,7 @@ class MosaicCollectionViewLayout: UICollectionViewFlowLayout { let columnIndex: Int = self._shortestColumnIndexInSection(section: section) let indexPath = IndexPath(item: idx, section: section) - let itemSize = self._itemSizeAtIndexPath(indexPath: indexPath); + let itemSize = self._itemSizeAtIndexPath(indexPath: indexPath) let xOffset = _sectionInset.left + (columnWidth + columnSpacing) * CGFloat(columnIndex) let yOffset = _columnHeights![section][columnIndex] @@ -136,14 +136,14 @@ class MosaicCollectionViewLayout: UICollectionViewFlowLayout { override func shouldInvalidateLayout(forBoundsChange newBounds: CGRect) -> Bool { if (!(self.collectionView?.bounds.size.equalTo(newBounds.size))!) { - return true; + return true } - return false; + return false } func _widthForSection (section: Int) -> CGFloat { - return self.collectionView!.bounds.size.width - _sectionInset.left - _sectionInset.right; + return self.collectionView!.bounds.size.width - _sectionInset.left - _sectionInset.right } func _columnWidthForSection(section: Int) -> CGFloat @@ -179,11 +179,11 @@ class MosaicCollectionViewLayout: UICollectionViewFlowLayout { func _tallestColumnIndexInSection(section: Int) -> Int { - var index: Int = 0; - var tallestHeight: CGFloat = 0; - _ = _columnHeights?[section].enumerated().map { (idx,height) in + var index: Int = 0 + var tallestHeight: CGFloat = 0 + _columnHeights?[section].enumerated().forEach { (idx,height) in if (height > tallestHeight) { - index = idx; + index = idx tallestHeight = height } } @@ -192,11 +192,11 @@ class MosaicCollectionViewLayout: UICollectionViewFlowLayout { func _shortestColumnIndexInSection(section: Int) -> Int { - var index: Int = 0; + var index: Int = 0 var shortestHeight: CGFloat = CGFloat.greatestFiniteMagnitude - _ = _columnHeights?[section].enumerated().map { (idx,height) in + _columnHeights?[section].enumerated().forEach { (idx,height) in if (height < shortestHeight) { - index = idx; + index = idx shortestHeight = height } } @@ -241,6 +241,6 @@ class MosaicCollectionViewLayoutInspector: NSObject, ASCollectionViewLayoutInspe } func scrollableDirections() -> ASScrollDirection { - return ASScrollDirectionVerticalDirections; + return ASScrollDirectionVerticalDirections } }