From 1f8b9173b889804b8e16f2f0dc33391a1219655d Mon Sep 17 00:00:00 2001 From: Eugene Kazaev Date: Mon, 11 Mar 2024 11:01:26 +0000 Subject: [PATCH] Reformatted code to swift 5.10 --- .swiftformat | 13 +++--- .../Classes/Core/ChatItemAlignment.swift | 2 - .../Classes/Core/ChatLayoutAttributes.swift | 8 ++-- .../Classes/Core/ChatLayoutDelegate.swift | 6 --- .../Core/ChatLayoutInvalidationContext.swift | 2 - .../Core/ChatLayoutPositionSnapshot.swift | 4 -- .../Classes/Core/ChatLayoutSettings.swift | 2 - .../Core/CollectionViewChatLayout.swift | 26 +++++------- .../Core/Extensions/CGRect+Extension.swift | 5 +-- .../Core/Extensions/IndexPath+Extension.swift | 2 - .../RandomAccessCollection+Extension.swift | 2 - .../Classes/Core/Model/ChangeItem.swift | 2 - ChatLayout/Classes/Core/Model/ItemKind.swift | 13 +++--- ChatLayout/Classes/Core/Model/ItemModel.swift | 4 -- ChatLayout/Classes/Core/Model/ItemPath.swift | 2 - ChatLayout/Classes/Core/Model/ItemSize.swift | 8 ++-- .../Classes/Core/Model/LayoutModel.swift | 4 -- .../Classes/Core/Model/ModelState.swift | 3 -- .../Classes/Core/Model/SectionModel.swift | 2 - .../Classes/Core/Model/StateController.swift | 7 +--- .../Extras/CellLayoutContainerView.swift | 12 ++---- .../ContainerCollectionReusableView.swift | 2 - .../Extras/ContainerCollectionViewCell.swift | 2 - .../ContainerCollectionViewCellDelegate.swift | 4 -- .../Classes/Extras/EdgeAligningView.swift | 4 -- .../Extensions/NSLayoutAnchor+Extension.swift | 21 ++++++---- .../NSLayoutDimension+Extension.swift | 42 +++++++++++-------- .../Classes/Extras/ImageMaskedView.swift | 4 -- .../Classes/Extras/MessageContainerView.swift | 2 - .../Extras/RoundedCornersContainerView.swift | 2 - .../Classes/Extras/StaticViewFactory.swift | 8 ---- .../Extras/SwappingContainerView.swift | 41 +++++++----------- Example/ChatLayout/AppDelegate.swift | 1 - .../Builder/ChatViewControllerBuilder.swift | 2 - Example/ChatLayout/Chat/Constants.swift | 2 - .../Chat/Controller/ChatController.swift | 2 - .../Controller/ChatControllerDelegate.swift | 2 - .../Controller/DefaultChatController.swift | 19 +++------ .../Helpers/DifferenceKit+Extension.swift | 4 -- .../Chat/Controller/Helpers/SetActor.swift | 11 ----- .../Image Loader/CachingImageLoader.swift | 2 - .../Image Loader/DefaultImageLoader.swift | 2 - .../Controller/Image Loader/ImageLoader.swift | 2 - .../Image Loader/ImageMessageSource.swift | 3 -- .../Controller/Keyboard/KeyboardInfo.swift | 2 - .../Keyboard/KeyboardListener.swift | 20 +++++---- .../Keyboard/KeyboardListenerDelegate.swift | 4 -- Example/ChatLayout/Chat/Model/Caches.swift | 10 ++--- .../Model/Caching/AsyncKeyValueCaching.swift | 4 -- .../Chat/Model/Caching/CacheError.swift | 2 - .../Model/Caching/Data/IterativeCache.swift | 6 +-- .../Model/Caching/Data/MemoryDataCache.swift | 6 --- .../Caching/Data/PersistentDataCache.swift | 2 - .../Caching/Data/PersistentlyCacheable.swift | 2 - .../Caching/Image/CacheableImageKey.swift | 2 - .../Caching/Image/ImageForUrlCache.swift | 2 - .../Chat/Model/Caching/KeyValueCaching.swift | 2 - .../Caching/Metadata/MetaDataCache.swift | 4 -- .../Chat/Model/ChatDateFormatter.swift | 4 -- .../Chat/Model/Data Objects/Cell.swift | 20 ++++----- .../Chat/Model/Data Objects/Message.swift | 20 --------- .../Chat/Model/Data Objects/RawMessage.swift | 4 -- .../Chat/Model/Data Objects/Section.swift | 4 -- .../Chat/Model/Data Objects/TypingState.swift | 2 - .../Chat/Model/Data Objects/User.swift | 10 ++--- .../Model/DefaultRandomDataProvider.swift | 6 --- .../ChatLayout/Chat/Model/TextGenerator.swift | 2 - .../Avatar View/AvatarPlaceholderView.swift | 2 - .../Chat/View/Avatar View/AvatarView.swift | 7 +--- .../Avatar View/AvatarViewController.swift | 2 - .../Chat/View/ChatViewController.swift | 29 ++++--------- .../ChatCollectionDataSource.swift | 2 - .../DefaultChatCollectionDataSource.swift | 11 ++--- .../DateAccessoryController.swift | 2 - .../DateAccessoryView.swift | 2 - .../EditingAccessoryController.swift | 4 -- .../EditingAccessoryView.swift | 7 +--- .../View/Image View/ImageController.swift | 2 - .../Chat/View/Image View/ImageView.swift | 2 - .../Chat/View/Image View/ImageViewState.swift | 2 - .../View/Other/BezierBubbleController.swift | 2 - .../Chat/View/Other/BezierMaskedView.swift | 6 +-- .../Chat/View/Other/EditNotifier.swift | 2 - .../View/Other/EditNotifierDelegate.swift | 6 --- .../FullCellContentBubbleController.swift | 2 - .../Chat/View/Other/MainContainerView.swift | 2 - .../Chat/View/Other/ManualAnimator.swift | 25 ++++++----- .../Chat/View/Other/SwipeNotifier.swift | 4 -- .../View/Other/TextBubbleController.swift | 2 - .../Chat/View/Other/UIView+Extension.swift | 2 - .../ChatLayout/Chat/View/ReloadDelegate.swift | 2 - .../Chat/View/Status View/StatusView.swift | 2 - .../TextMessageController.swift | 2 - .../Text Message View/TextMessageView.swift | 4 -- .../Chat/View/URL View/URLController.swift | 3 -- .../Chat/View/URL View/URLSource.swift | 7 +--- .../Chat/View/URL View/URLView.swift | 2 - .../ChatLayout/ProcessInfo+Extension.swift | 2 - Example/ChatLayout/SceneDelegate.swift | 1 - Example/Tests/HelpersTests.swift | 14 +++---- Example/Tests/MockCollectionLayout.swift | 2 - .../MockUICollectionViewUpdateItem.swift | 2 - Example/Tests/PerformanceTests.swift | 15 +++---- .../Tests/StateControllerInternalTests.swift | 2 - .../StateControllerProcessUpdatesTests.swift | 2 - 105 files changed, 171 insertions(+), 471 deletions(-) diff --git a/.swiftformat b/.swiftformat index 167ff6a7..71a6f70a 100644 --- a/.swiftformat +++ b/.swiftformat @@ -24,17 +24,18 @@ --octalgrouping none --operatorfunc spaced --patternlet hoist ---self remove ---selfrequired +--selfrequired --semicolons inline --stripunusedargs closure-only --tabwidth unspecified ---trailingclosures --trimwhitespace always --wraparguments preserve --wrapcollections preserve --xcodeindentation disabled --modifierorder public,override ---disable blankLinesAtEndOfScope,blankLinesAtStartOfScope,wrapMultilineStatementBraces,preferKeyPath,preferForLoop ---enable isEmpty ---exclude Pods,docs,Example/Pods +--nevertrailing map, flatMap, compactMap +--funcattributes prev-line +--typeattributes prev-line +--disable wrapMultilineStatementBraces, preferKeyPath, trailingclosures, preferForLoop,conditionalAssignment +--enable isEmpty,wrapConditionalBodies,noExplicitOwnership,wrapEnumCases,wrapSwitchCases,sortSwitchCases,wrapAttributes +--exclude Pods,docs,Example/Pods,RecyclerView/Classes/Utils/Stolen diff --git a/ChatLayout/Classes/Core/ChatItemAlignment.swift b/ChatLayout/Classes/Core/ChatItemAlignment.swift index 5af4910b..20f103bd 100644 --- a/ChatLayout/Classes/Core/ChatItemAlignment.swift +++ b/ChatLayout/Classes/Core/ChatItemAlignment.swift @@ -15,7 +15,6 @@ import UIKit /// Represent item alignment in collection view layout public enum ChatItemAlignment: Hashable { - /// Should be aligned at the leading edge of the layout. That includes all the additional content offsets. case leading @@ -27,5 +26,4 @@ public enum ChatItemAlignment: Hashable { /// Should be aligned using the full width of the available content width. case fullWidth - } diff --git a/ChatLayout/Classes/Core/ChatLayoutAttributes.swift b/ChatLayout/Classes/Core/ChatLayoutAttributes.swift index 7bddc118..63eb5040 100644 --- a/ChatLayout/Classes/Core/ChatLayoutAttributes.swift +++ b/ChatLayout/Classes/Core/ChatLayoutAttributes.swift @@ -15,7 +15,6 @@ import UIKit /// Custom implementation of `UICollectionViewLayoutAttributes` public final class ChatLayoutAttributes: UICollectionViewLayoutAttributes { - /// Alignment of the current item. Can be changed within `UICollectionViewCell.preferredLayoutAttributesFitting(...)` public var alignment: ChatItemAlignment = .fullWidth @@ -79,11 +78,11 @@ public final class ChatLayoutAttributes: UICollectionViewLayoutAttributes { public var kind: ItemKind { switch (representedElementCategory, representedElementKind) { case (.cell, nil): - return .cell + .cell case (.supplementaryView, .some(UICollectionView.elementKindSectionHeader)): - return .header + .header case (.supplementaryView, .some(UICollectionView.elementKindSectionFooter)): - return .footer + .footer default: preconditionFailure("Unsupported element kind.") } @@ -95,5 +94,4 @@ public final class ChatLayoutAttributes: UICollectionViewLayoutAttributes { } return typedCopy } - } diff --git a/ChatLayout/Classes/Core/ChatLayoutDelegate.swift b/ChatLayout/Classes/Core/ChatLayoutDelegate.swift index 08f7653a..234ab3c5 100644 --- a/ChatLayout/Classes/Core/ChatLayoutDelegate.swift +++ b/ChatLayout/Classes/Core/ChatLayoutDelegate.swift @@ -15,18 +15,15 @@ import UIKit /// Represents the point in time when `CollectionViewChatLayout` asks about layout attributes modification. public enum InitialAttributesRequestType: Hashable { - /// `UICollectionView` initially asks about the layout of an item. case initial /// An item is being invalidated. case invalidation - } /// `CollectionViewChatLayout` delegate public protocol ChatLayoutDelegate: AnyObject { - /// `CollectionViewChatLayout` will call this method to ask if it should present the header in the current layout. /// - Parameters: /// - chatLayout: `CollectionViewChatLayout` reference. @@ -121,12 +118,10 @@ public protocol ChatLayoutDelegate: AnyObject { /// - sectionIndex: Index of the section. func interSectionSpacing(_ chatLayout: CollectionViewChatLayout, after sectionIndex: Int) -> CGFloat? - } /// Default extension. public extension ChatLayoutDelegate { - /// Default implementation returns: `false`. func shouldPresentHeader(_ chatLayout: CollectionViewChatLayout, at sectionIndex: Int) -> Bool { @@ -182,5 +177,4 @@ public extension ChatLayoutDelegate { after sectionIndex: Int) -> CGFloat? { nil } - } diff --git a/ChatLayout/Classes/Core/ChatLayoutInvalidationContext.swift b/ChatLayout/Classes/Core/ChatLayoutInvalidationContext.swift index 16d7f5a9..4b55a97b 100644 --- a/ChatLayout/Classes/Core/ChatLayoutInvalidationContext.swift +++ b/ChatLayout/Classes/Core/ChatLayoutInvalidationContext.swift @@ -15,9 +15,7 @@ import UIKit /// Custom implementation of `UICollectionViewLayoutInvalidationContext` public final class ChatLayoutInvalidationContext: UICollectionViewLayoutInvalidationContext { - /// Indicates whether to recompute the positions and sizes of the items based on the current /// collection view and delegate layout metrics. public var invalidateLayoutMetrics = true - } diff --git a/ChatLayout/Classes/Core/ChatLayoutPositionSnapshot.swift b/ChatLayout/Classes/Core/ChatLayoutPositionSnapshot.swift index 8d647703..115c8998 100644 --- a/ChatLayout/Classes/Core/ChatLayoutPositionSnapshot.swift +++ b/ChatLayout/Classes/Core/ChatLayoutPositionSnapshot.swift @@ -15,16 +15,13 @@ import UIKit /// Represents content offset position expressed by the specific item and it offset from the top or bottom edge. public struct ChatLayoutPositionSnapshot: Hashable { - /// Represents the edge. public enum Edge: Hashable { - /// Top edge of the `UICollectionView` case top /// Bottom edge of the `UICollectionView` case bottom - } /// Item's `IndexPath` @@ -54,5 +51,4 @@ public struct ChatLayoutPositionSnapshot: Hashable { self.offset = offset self.kind = kind } - } diff --git a/ChatLayout/Classes/Core/ChatLayoutSettings.swift b/ChatLayout/Classes/Core/ChatLayoutSettings.swift index 53e0328c..fcb3e34f 100644 --- a/ChatLayout/Classes/Core/ChatLayoutSettings.swift +++ b/ChatLayout/Classes/Core/ChatLayoutSettings.swift @@ -15,7 +15,6 @@ import UIKit /// `CollectionViewChatLayout` settings. public struct ChatLayoutSettings: Equatable { - /// Estimated item size for `CollectionViewChatLayout`. This value will be used as the initial size of the item and the final size /// will be calculated using `UICollectionViewCell.preferredLayoutAttributesFitting(...)`. public var estimatedItemSize: CGSize? @@ -28,5 +27,4 @@ public struct ChatLayoutSettings: Equatable { /// Additional insets for the `CollectionViewChatLayout` content. public var additionalInsets: UIEdgeInsets = .zero - } diff --git a/ChatLayout/Classes/Core/CollectionViewChatLayout.swift b/ChatLayout/Classes/Core/CollectionViewChatLayout.swift index 1f7485f1..a372a762 100644 --- a/ChatLayout/Classes/Core/CollectionViewChatLayout.swift +++ b/ChatLayout/Classes/Core/CollectionViewChatLayout.swift @@ -36,7 +36,6 @@ import UIKit /// /// `CollectionViewChatLayout.restoreContentOffset(...)` open class CollectionViewChatLayout: UICollectionViewLayout { - // MARK: Custom Properties /// `CollectionViewChatLayout` delegate. @@ -169,7 +168,6 @@ open class CollectionViewChatLayout: UICollectionViewLayout { // MARK: Private Properties private struct PrepareActions: OptionSet { - let rawValue: UInt static let recreateSectionModels = PrepareActions(rawValue: 1 << 0) @@ -177,15 +175,12 @@ open class CollectionViewChatLayout: UICollectionViewLayout { static let cachePreviousWidth = PrepareActions(rawValue: 1 << 2) static let cachePreviousContentInsets = PrepareActions(rawValue: 1 << 3) static let switchStates = PrepareActions(rawValue: 1 << 4) - } private struct InvalidationActions: OptionSet { - let rawValue: UInt static let shouldInvalidateOnBoundsChange = InvalidationActions(rawValue: 1 << 0) - } private lazy var controller = StateController(layoutRepresentation: self) @@ -220,9 +215,15 @@ open class CollectionViewChatLayout: UICollectionViewLayout { // MARK: IOS 15.1 fix flags private var needsIOS15_1IssueFix: Bool { - guard enableIOS15_1Fix else { return false } - guard #unavailable(iOS 15.2) else { return false } - guard #available(iOS 15.1, *) else { return false } + guard enableIOS15_1Fix else { + return false + } + guard #unavailable(iOS 15.2) else { + return false + } + guard #available(iOS 15.1, *) else { + return false + } return isUserInitiatedScrolling && !controller.isAnimatedBoundsChange } @@ -599,7 +600,8 @@ open class CollectionViewChatLayout: UICollectionViewLayout { switch preferredMessageAttributes.kind { case .cell: context.invalidateItems(at: [preferredMessageAttributes.indexPath]) - case .header, .footer: + case .footer, + .header: context.invalidateSupplementaryElements(ofKind: preferredMessageAttributes.kind.supplementaryElementStringType, at: [preferredMessageAttributes.indexPath]) } } @@ -939,11 +941,9 @@ open class CollectionViewChatLayout: UICollectionViewLayout { } return attributes } - } extension CollectionViewChatLayout { - func configuration(for element: ItemKind, at indexPath: IndexPath) -> ItemModel.Configuration { let itemSize = estimatedSize(for: element, at: indexPath) let interItemSpacing: CGFloat @@ -1023,11 +1023,9 @@ extension CollectionViewChatLayout { invalidatedAttributes[kind] = [] } } - } extension CollectionViewChatLayout: ChatLayoutRepresentation { - func numberOfItems(in section: Int) -> Int { guard let collectionView else { return .zero @@ -1056,7 +1054,6 @@ extension CollectionViewChatLayout: ChatLayoutRepresentation { } extension CollectionViewChatLayout { - private var maxPossibleContentOffset: CGPoint { guard let collectionView else { return .zero @@ -1071,5 +1068,4 @@ extension CollectionViewChatLayout { } return collectionView.isDragging || collectionView.isDecelerating } - } diff --git a/ChatLayout/Classes/Core/Extensions/CGRect+Extension.swift b/ChatLayout/Classes/Core/Extensions/CGRect+Extension.swift index 8a44a653..261efa11 100644 --- a/ChatLayout/Classes/Core/Extensions/CGRect+Extension.swift +++ b/ChatLayout/Classes/Core/Extensions/CGRect+Extension.swift @@ -14,7 +14,6 @@ import Foundation import UIKit extension CGRect { - var higherPoint: CGPoint { origin } @@ -27,9 +26,9 @@ extension CGRect { CGPoint(x: origin.x + size.width / 2, y: origin.y + size.height / 2) } - @inline(__always) mutating func offsettingBy(dx: CGFloat, dy: CGFloat) { + @inline(__always) + mutating func offsettingBy(dx: CGFloat, dy: CGFloat) { origin.x += dx origin.y += dy } - } diff --git a/ChatLayout/Classes/Core/Extensions/IndexPath+Extension.swift b/ChatLayout/Classes/Core/Extensions/IndexPath+Extension.swift index b6ba84a9..1421d0d1 100644 --- a/ChatLayout/Classes/Core/Extensions/IndexPath+Extension.swift +++ b/ChatLayout/Classes/Core/Extensions/IndexPath+Extension.swift @@ -13,9 +13,7 @@ import Foundation extension IndexPath { - var itemPath: ItemPath { ItemPath(for: self) } - } diff --git a/ChatLayout/Classes/Core/Extensions/RandomAccessCollection+Extension.swift b/ChatLayout/Classes/Core/Extensions/RandomAccessCollection+Extension.swift index a10c57a9..57498467 100644 --- a/ChatLayout/Classes/Core/Extensions/RandomAccessCollection+Extension.swift +++ b/ChatLayout/Classes/Core/Extensions/RandomAccessCollection+Extension.swift @@ -13,7 +13,6 @@ import Foundation extension RandomAccessCollection where Index == Int { - func binarySearch(predicate: (Element) -> ComparisonResult) -> Index? { var lowerBound = startIndex var upperBound = endIndex @@ -79,5 +78,4 @@ extension RandomAccessCollection where Index == Int { return Array(self[lowerBound...upperBound]) } - } diff --git a/ChatLayout/Classes/Core/Model/ChangeItem.swift b/ChatLayout/Classes/Core/Model/ChangeItem.swift index d5324ed7..94133d98 100644 --- a/ChatLayout/Classes/Core/Model/ChangeItem.swift +++ b/ChatLayout/Classes/Core/Model/ChangeItem.swift @@ -15,7 +15,6 @@ import UIKit /// Internal replacement for `UICollectionViewUpdateItem`. enum ChangeItem: Equatable { - /// Delete section at `sectionIndex` case sectionDelete(sectionIndex: Int) @@ -98,5 +97,4 @@ enum ChangeItem: Equatable { return nil } } - } diff --git a/ChatLayout/Classes/Core/Model/ItemKind.swift b/ChatLayout/Classes/Core/Model/ItemKind.swift index 7651e635..4cddc4b9 100644 --- a/ChatLayout/Classes/Core/Model/ItemKind.swift +++ b/ChatLayout/Classes/Core/Model/ItemKind.swift @@ -15,7 +15,6 @@ import UIKit /// Type of the item supported by `CollectionViewChatLayout` public enum ItemKind: CaseIterable, Hashable { - /// Header item case header @@ -40,9 +39,10 @@ public enum ItemKind: CaseIterable, Hashable { public var isSupplementaryItem: Bool { switch self { case .cell: - return false - case .header, .footer: - return true + false + case .footer, + .header: + true } } @@ -51,10 +51,9 @@ public enum ItemKind: CaseIterable, Hashable { case .cell: preconditionFailure("Cell type is not a supplementary view.") case .header: - return UICollectionView.elementKindSectionHeader + UICollectionView.elementKindSectionHeader case .footer: - return UICollectionView.elementKindSectionFooter + UICollectionView.elementKindSectionFooter } } - } diff --git a/ChatLayout/Classes/Core/Model/ItemModel.swift b/ChatLayout/Classes/Core/Model/ItemModel.swift index df5a6887..e13ab816 100644 --- a/ChatLayout/Classes/Core/Model/ItemModel.swift +++ b/ChatLayout/Classes/Core/Model/ItemModel.swift @@ -14,9 +14,7 @@ import Foundation import UIKit struct ItemModel { - struct Configuration { - let alignment: ChatItemAlignment let preferredSize: CGSize @@ -24,7 +22,6 @@ struct ItemModel { let calculatedSize: CGSize? let interItemSpacing: CGFloat - } let id: UUID @@ -72,5 +69,4 @@ struct ItemModel { self.calculatedSize = nil preferredSize = calculatedSize } - } diff --git a/ChatLayout/Classes/Core/Model/ItemPath.swift b/ChatLayout/Classes/Core/Model/ItemPath.swift index e52b626b..09be72ea 100644 --- a/ChatLayout/Classes/Core/Model/ItemPath.swift +++ b/ChatLayout/Classes/Core/Model/ItemPath.swift @@ -18,7 +18,6 @@ import Foundation /// On an iPhone X, compiled with -Os optimizations, it's about 35x faster to initialize this struct /// compared to an `IndexPath`. struct ItemPath: Hashable { - let section: Int let item: Int @@ -36,5 +35,4 @@ struct ItemPath: Hashable { section = indexPath.section item = indexPath.item } - } diff --git a/ChatLayout/Classes/Core/Model/ItemSize.swift b/ChatLayout/Classes/Core/Model/ItemSize.swift index 8b3d67df..674732d3 100644 --- a/ChatLayout/Classes/Core/Model/ItemSize.swift +++ b/ChatLayout/Classes/Core/Model/ItemSize.swift @@ -15,7 +15,6 @@ import UIKit /// Represents desired item size. public enum ItemSize: Hashable { - /// Item size should be fully calculated by the `CollectionViewChatLayout`. /// Initial estimated size will be taken from `ChatLayoutSettings`. case auto @@ -41,11 +40,11 @@ public enum ItemSize: Hashable { public var caseType: CaseType { switch self { case .auto: - return .auto + .auto case .estimated: - return .estimated + .estimated case .exact: - return .exact + .exact } } @@ -62,5 +61,4 @@ public enum ItemSize: Hashable { hasher.combine(size.height) } } - } diff --git a/ChatLayout/Classes/Core/Model/LayoutModel.swift b/ChatLayout/Classes/Core/Model/LayoutModel.swift index 31f51f6a..9e2efc65 100644 --- a/ChatLayout/Classes/Core/Model/LayoutModel.swift +++ b/ChatLayout/Classes/Core/Model/LayoutModel.swift @@ -14,13 +14,10 @@ import Foundation import UIKit final class LayoutModel { - private struct ItemUUIDKey: Hashable { - let kind: ItemKind let id: UUID - } private(set) var sections: ContiguousArray> @@ -207,5 +204,4 @@ final class LayoutModel { itemPathByIdentifierCache = nil sectionIndexByIdentifierCache = nil } - } diff --git a/ChatLayout/Classes/Core/Model/ModelState.swift b/ChatLayout/Classes/Core/Model/ModelState.swift index 15a884c0..75e15e7b 100644 --- a/ChatLayout/Classes/Core/Model/ModelState.swift +++ b/ChatLayout/Classes/Core/Model/ModelState.swift @@ -13,9 +13,6 @@ import Foundation enum ModelState: Hashable, CaseIterable { - case beforeUpdate - case afterUpdate - } diff --git a/ChatLayout/Classes/Core/Model/SectionModel.swift b/ChatLayout/Classes/Core/Model/SectionModel.swift index 626beddc..71112c0a 100644 --- a/ChatLayout/Classes/Core/Model/SectionModel.swift +++ b/ChatLayout/Classes/Core/Model/SectionModel.swift @@ -14,7 +14,6 @@ import Foundation import UIKit struct SectionModel { - let id: UUID let interSectionSpacing: CGFloat @@ -190,5 +189,4 @@ struct SectionModel { } items.remove(at: index) } - } diff --git a/ChatLayout/Classes/Core/Model/StateController.swift b/ChatLayout/Classes/Core/Model/StateController.swift index 9fe7fef5..d30b9de1 100644 --- a/ChatLayout/Classes/Core/Model/StateController.swift +++ b/ChatLayout/Classes/Core/Model/StateController.swift @@ -15,7 +15,6 @@ import UIKit /// This protocol exists only to serve an ability to unit test `StateController`. protocol ChatLayoutRepresentation: AnyObject { - var settings: ChatLayoutSettings { get } var viewSize: CGSize { get } @@ -42,10 +41,8 @@ protocol ChatLayoutRepresentation: AnyObject { } final class StateController { - // Helps to reduce the amount of looses in bridging calls to objc `UICollectionView` getter methods. struct AdditionalLayoutAttributes { - fileprivate let additionalInsets: UIEdgeInsets fileprivate let viewSize: CGSize @@ -410,7 +407,8 @@ final class StateController { } let rowModel = sectionModel.items[itemPath.item] return rowModel.id - case .header, .footer: + case .footer, + .header: guard let item = item(for: ItemPath(item: 0, section: itemPath.section), kind: kind, at: state) else { return nil } @@ -1235,5 +1233,4 @@ final class StateController { return ItemPath(item: itemIndex, section: sectionIndex) } } - } diff --git a/ChatLayout/Classes/Extras/CellLayoutContainerView.swift b/ChatLayout/Classes/Extras/CellLayoutContainerView.swift index 4b2170c6..c1c0746f 100644 --- a/ChatLayout/Classes/Extras/CellLayoutContainerView.swift +++ b/ChatLayout/Classes/Extras/CellLayoutContainerView.swift @@ -15,7 +15,6 @@ import UIKit /// Alignment for `CellLayoutContainerView` that corresponds to `UIStackView.Alignment` public enum CellLayoutContainerViewAlignment { - /// Align the top and bottom edges of horizontally stacked items tightly to the container. case fill @@ -30,20 +29,18 @@ public enum CellLayoutContainerViewAlignment { fileprivate var stackAlignment: UIStackView.Alignment { switch self { - case .fill: return .fill - case .top: return .top - case .center: return .center - case .bottom: return .bottom + case .fill: .fill + case .top: .top + case .center: .center + case .bottom: .bottom } } - } /// `CellLayoutContainerView` is a container view that helps to arrange the views in a horizontal cell-alike layout with an optional `LeadingAccessory` first, /// a `CustomView` next and am optional `TrailingAccessory` last. Use `VoidViewFactory` to specify that `LeadingAccessory` or `TrailingAccessory` views should not be /// allocated. public final class CellLayoutContainerView: UIView { - /// Leading accessory view. public lazy var leadingView: LeadingAccessory.View? = LeadingAccessory.buildView(within: bounds) @@ -144,5 +141,4 @@ public final class CellLayoutContainerView: UICollectionReusableView { - /// Default reuse identifier is set with the class name. public static var reuseIdentifier: String { String(describing: self) @@ -91,5 +90,4 @@ public final class ContainerCollectionReusableView: UICollec customView.trailingAnchor.constraint(equalTo: layoutMarginsGuide.trailingAnchor) ]) } - } diff --git a/ChatLayout/Classes/Extras/ContainerCollectionViewCell.swift b/ChatLayout/Classes/Extras/ContainerCollectionViewCell.swift index e2faf583..4cda48d9 100644 --- a/ChatLayout/Classes/Extras/ContainerCollectionViewCell.swift +++ b/ChatLayout/Classes/Extras/ContainerCollectionViewCell.swift @@ -15,7 +15,6 @@ import UIKit /// A container `UICollectionViewCell` that constraints its contained view to its margins. public final class ContainerCollectionViewCell: UICollectionViewCell { - /// Default reuse identifier is set with the class name. public static var reuseIdentifier: String { String(describing: self) @@ -93,5 +92,4 @@ public final class ContainerCollectionViewCell: UICollection customView.trailingAnchor.constraint(equalTo: contentView.layoutMarginsGuide.trailingAnchor) ]) } - } diff --git a/ChatLayout/Classes/Extras/ContainerCollectionViewCellDelegate.swift b/ChatLayout/Classes/Extras/ContainerCollectionViewCellDelegate.swift index 48ed14fe..d2dced68 100644 --- a/ChatLayout/Classes/Extras/ContainerCollectionViewCellDelegate.swift +++ b/ChatLayout/Classes/Extras/ContainerCollectionViewCellDelegate.swift @@ -16,7 +16,6 @@ import UIKit /// A delegate of `ContainerCollectionViewCell`/`ContainerCollectionReusableView` should implement this methods if /// it is required to participate in containers lifecycle. public protocol ContainerCollectionViewCellDelegate: AnyObject { - /// Perform any clean up necessary to prepare the view for use again. func prepareForReuse() @@ -40,12 +39,10 @@ public protocol ContainerCollectionViewCellDelegate: AnyObject { /// Keep in mind that this method can be called multiple times. /// - Parameter layoutAttributes: `ChatLayoutAttributes` provided by `CollectionViewChatLayout`. func apply(_ layoutAttributes: ChatLayoutAttributes) - } /// Default extension to make the methods optional for implementation in the successor public extension ContainerCollectionViewCellDelegate { - /// Default implementation does nothing. func prepareForReuse() {} @@ -59,5 +56,4 @@ public extension ContainerCollectionViewCellDelegate { /// Default implementation does nothing. func apply(_ layoutAttributes: ChatLayoutAttributes) {} - } diff --git a/ChatLayout/Classes/Extras/EdgeAligningView.swift b/ChatLayout/Classes/Extras/EdgeAligningView.swift index 7d7e1891..12c103e8 100644 --- a/ChatLayout/Classes/Extras/EdgeAligningView.swift +++ b/ChatLayout/Classes/Extras/EdgeAligningView.swift @@ -16,10 +16,8 @@ import UIKit /// Container view that allows its `CustomView` to have lose connection to the margins of the container according to the /// settings provided in `EdgeAligningView.flexibleEdges` public final class EdgeAligningView: UIView { - /// Represents an edge of `EdgeAligningView` public enum Edge: CaseIterable { - /// Top edge case top @@ -31,7 +29,6 @@ public final class EdgeAligningView: UIView { /// Bottom edge case bottom - } /// Set of edge constraints to be set as loose. @@ -205,5 +202,4 @@ public final class EdgeAligningView: UIView { .leading: view.leadingAnchor.constraint(greaterThanOrEqualTo: layoutMarginsGuide.leadingAnchor, priority: preferredPriority), .trailing: view.trailingAnchor.constraint(lessThanOrEqualTo: layoutMarginsGuide.trailingAnchor, priority: preferredPriority)] } - } diff --git a/ChatLayout/Classes/Extras/Extensions/NSLayoutAnchor+Extension.swift b/ChatLayout/Classes/Extras/Extensions/NSLayoutAnchor+Extension.swift index f9707aa6..d2592bf7 100644 --- a/ChatLayout/Classes/Extras/Extensions/NSLayoutAnchor+Extension.swift +++ b/ChatLayout/Classes/Extras/Extensions/NSLayoutAnchor+Extension.swift @@ -14,25 +14,28 @@ import Foundation import UIKit extension NSLayoutAnchor { - @objc func constraint(equalTo anchor: NSLayoutAnchor, - constant c: CGFloat = 0, - priority: UILayoutPriority) -> NSLayoutConstraint { + @objc + func constraint(equalTo anchor: NSLayoutAnchor, + constant c: CGFloat = 0, + priority: UILayoutPriority) -> NSLayoutConstraint { let constraint = constraint(equalTo: anchor, constant: c) constraint.priority = priority return constraint } - @objc func constraint(greaterThanOrEqualTo anchor: NSLayoutAnchor, - constant c: CGFloat = 0, - priority: UILayoutPriority) -> NSLayoutConstraint { + @objc + func constraint(greaterThanOrEqualTo anchor: NSLayoutAnchor, + constant c: CGFloat = 0, + priority: UILayoutPriority) -> NSLayoutConstraint { let constraint = constraint(greaterThanOrEqualTo: anchor, constant: c) constraint.priority = priority return constraint } - @objc func constraint(lessThanOrEqualTo anchor: NSLayoutAnchor, - constant c: CGFloat = 0, - priority: UILayoutPriority) -> NSLayoutConstraint { + @objc + func constraint(lessThanOrEqualTo anchor: NSLayoutAnchor, + constant c: CGFloat = 0, + priority: UILayoutPriority) -> NSLayoutConstraint { let constraint = constraint(lessThanOrEqualTo: anchor, constant: c) constraint.priority = priority return constraint diff --git a/ChatLayout/Classes/Extras/Extensions/NSLayoutDimension+Extension.swift b/ChatLayout/Classes/Extras/Extensions/NSLayoutDimension+Extension.swift index c3d870cf..bc16d473 100644 --- a/ChatLayout/Classes/Extras/Extensions/NSLayoutDimension+Extension.swift +++ b/ChatLayout/Classes/Extras/Extensions/NSLayoutDimension+Extension.swift @@ -14,49 +14,55 @@ import Foundation import UIKit extension NSLayoutDimension { - @objc func constraint(equalTo anchor: NSLayoutDimension, - multiplier m: CGFloat = 1, - constant c: CGFloat = 0, - priority: UILayoutPriority) -> NSLayoutConstraint { + @objc + func constraint(equalTo anchor: NSLayoutDimension, + multiplier m: CGFloat = 1, + constant c: CGFloat = 0, + priority: UILayoutPriority) -> NSLayoutConstraint { let constraint = constraint(equalTo: anchor, multiplier: m, constant: c) constraint.priority = priority return constraint } - @objc func constraint(greaterThanOrEqualTo anchor: NSLayoutDimension, - multiplier m: CGFloat = 1, - constant c: CGFloat = 0, - priority: UILayoutPriority) -> NSLayoutConstraint { + @objc + func constraint(greaterThanOrEqualTo anchor: NSLayoutDimension, + multiplier m: CGFloat = 1, + constant c: CGFloat = 0, + priority: UILayoutPriority) -> NSLayoutConstraint { let constraint = constraint(greaterThanOrEqualTo: anchor, multiplier: m, constant: c) constraint.priority = priority return constraint } - @objc func constraint(lessThanOrEqualTo anchor: NSLayoutDimension, - multiplier m: CGFloat = 1, - constant c: CGFloat = 0, - priority: UILayoutPriority) -> NSLayoutConstraint { + @objc + func constraint(lessThanOrEqualTo anchor: NSLayoutDimension, + multiplier m: CGFloat = 1, + constant c: CGFloat = 0, + priority: UILayoutPriority) -> NSLayoutConstraint { let constraint = constraint(lessThanOrEqualTo: anchor, multiplier: m, constant: c) constraint.priority = priority return constraint } - @objc func constraint(equalToConstant c: CGFloat, - priority: UILayoutPriority) -> NSLayoutConstraint { + @objc + func constraint(equalToConstant c: CGFloat, + priority: UILayoutPriority) -> NSLayoutConstraint { let constraint = constraint(equalToConstant: c) constraint.priority = priority return constraint } - @objc func constraint(greaterThanOrEqualToConstant c: CGFloat, - priority: UILayoutPriority) -> NSLayoutConstraint { + @objc + func constraint(greaterThanOrEqualToConstant c: CGFloat, + priority: UILayoutPriority) -> NSLayoutConstraint { let constraint = constraint(greaterThanOrEqualToConstant: c) constraint.priority = priority return constraint } - @objc func constraint(lessThanOrEqualToConstant c: CGFloat, - priority: UILayoutPriority) -> NSLayoutConstraint { + @objc + func constraint(lessThanOrEqualToConstant c: CGFloat, + priority: UILayoutPriority) -> NSLayoutConstraint { let constraint = constraint(lessThanOrEqualToConstant: c) constraint.priority = priority return constraint diff --git a/ChatLayout/Classes/Extras/ImageMaskedView.swift b/ChatLayout/Classes/Extras/ImageMaskedView.swift index d859abd1..76650083 100644 --- a/ChatLayout/Classes/Extras/ImageMaskedView.swift +++ b/ChatLayout/Classes/Extras/ImageMaskedView.swift @@ -15,18 +15,15 @@ import UIKit /// A transformation to apply to the `ImageMaskedView.maskingImage` public enum ImageMaskedViewTransformation { - /// Keep image as it is. case asIs /// Flip image vertically. case flippedVertically - } /// A container view that masks its contained view with an image provided. public final class ImageMaskedView: UIView { - /// Contained view. public lazy var customView = CustomView(frame: bounds) @@ -116,5 +113,4 @@ public final class ImageMaskedView: UIView { imageView.frame = bounds } } - } diff --git a/ChatLayout/Classes/Extras/MessageContainerView.swift b/ChatLayout/Classes/Extras/MessageContainerView.swift index 94346eb7..2ef8b170 100644 --- a/ChatLayout/Classes/Extras/MessageContainerView.swift +++ b/ChatLayout/Classes/Extras/MessageContainerView.swift @@ -15,7 +15,6 @@ import UIKit /// A container view that helps to layout the message view and its accessory public final class MessageContainerView: UIView { - private lazy var stackView = UIStackView(frame: bounds) /// An accessory view. @@ -84,5 +83,4 @@ public final class MessageContainerView: UIView { - /// Corner radius. If not provided then the half of the current view height will be used. public var cornerRadius: CGFloat? @@ -59,5 +58,4 @@ public final class RoundedCornersContainerView: UIView { layer.cornerRadius = cornerRadius ?? frame.height / 2 clipsToBounds = true } - } diff --git a/ChatLayout/Classes/Extras/StaticViewFactory.swift b/ChatLayout/Classes/Extras/StaticViewFactory.swift index 38433ad0..6d87ba96 100644 --- a/ChatLayout/Classes/Extras/StaticViewFactory.swift +++ b/ChatLayout/Classes/Extras/StaticViewFactory.swift @@ -15,7 +15,6 @@ import UIKit /// A factory that creates optional contained `UIView`s should conform to this protocol. public protocol StaticViewFactory { - /// A type of the view to build. associatedtype View: UIView @@ -23,24 +22,19 @@ public protocol StaticViewFactory { /// - Parameter bounds: A bounds rect of the container. /// - Returns: Build `UIView` instance. static func buildView(within bounds: CGRect) -> View? - } /// Default extension build the `UIView` using its default constructor. public extension StaticViewFactory where Self: UIView { - static func buildView(within bounds: CGRect) -> Self? { Self(frame: bounds) } - } /// Use this factory to specify that this view should not be build and should be equal to nil within the container. public struct VoidViewFactory: StaticViewFactory { - /// Nil view placeholder type. public final class VoidView: UIView { - @available(*, unavailable, message: "This view can not be instantiated.") public required init?(coder aDecoder: NSCoder) { fatalError("This view can not be instantiated.") @@ -55,11 +49,9 @@ public struct VoidViewFactory: StaticViewFactory { public init() { fatalError("This view can not be instantiated.") } - } public static func buildView(within bounds: CGRect) -> VoidView? { nil } - } diff --git a/ChatLayout/Classes/Extras/SwappingContainerView.swift b/ChatLayout/Classes/Extras/SwappingContainerView.swift index 7b9a49f0..6977572c 100644 --- a/ChatLayout/Classes/Extras/SwappingContainerView.swift +++ b/ChatLayout/Classes/Extras/SwappingContainerView.swift @@ -16,27 +16,22 @@ import UIKit /// This container view is designed to hold two `UIView` elements and arrange them in a horizontal or vertical axis. /// It also allows to easily change the order of the views if needed. public final class SwappingContainerView: UIView { - /// Keys that specify a horizontal or vertical layout constraint between views. public enum Axis: Hashable { - /// The constraint applied when laying out the horizontal relationship between views. case horizontal /// The constraint applied when laying out the vertical relationship between views. case vertical - } /// Keys that specify a distribution of the contained views. public enum Distribution: Hashable { - /// The `AccessoryView` should be positioned before the `CustomView`. case accessoryFirst /// The `AccessoryView` should be positioned after the `CustomView`. case accessoryLast - } /// The layout of the arranged subviews along the axis. @@ -112,7 +107,6 @@ public final class SwappingContainerView [NSLayoutConstraint] { switch axis { case .horizontal: - return [ + [ accessoryView.trailingAnchor.constraint(equalTo: customView.leadingAnchor, constant: spacing, priority: spacingPriority()), accessoryView.leadingAnchor.constraint(equalTo: layoutMarginsGuide.leadingAnchor, priority: preferredPriority), customView.trailingAnchor.constraint(equalTo: layoutMarginsGuide.trailingAnchor, priority: preferredPriority) ] case .vertical: - return [ + [ accessoryView.bottomAnchor.constraint(equalTo: customView.topAnchor, constant: spacing, priority: spacingPriority()), accessoryView.topAnchor.constraint(equalTo: layoutMarginsGuide.topAnchor, priority: preferredPriority), customView.bottomAnchor.constraint(equalTo: layoutMarginsGuide.bottomAnchor, priority: preferredPriority) @@ -347,13 +339,13 @@ public final class SwappingContainerView [NSLayoutConstraint] { switch axis { case .horizontal: - return [ + [ customView.trailingAnchor.constraint(equalTo: accessoryView.leadingAnchor, constant: -spacing, priority: spacingPriority()), customView.leadingAnchor.constraint(equalTo: layoutMarginsGuide.leadingAnchor, priority: preferredPriority), accessoryView.trailingAnchor.constraint(equalTo: layoutMarginsGuide.trailingAnchor, priority: preferredPriority) ] case .vertical: - return [ + [ customView.bottomAnchor.constraint(equalTo: accessoryView.topAnchor, constant: -spacing, priority: spacingPriority()), customView.topAnchor.constraint(equalTo: layoutMarginsGuide.topAnchor, priority: preferredPriority), accessoryView.bottomAnchor.constraint(equalTo: layoutMarginsGuide.bottomAnchor, priority: preferredPriority) @@ -364,12 +356,12 @@ public final class SwappingContainerView [NSLayoutConstraint] { switch axis { case .horizontal: - return [ + [ accessoryView.leadingAnchor.constraint(equalTo: layoutMarginsGuide.leadingAnchor, priority: preferredPriority), accessoryView.trailingAnchor.constraint(equalTo: layoutMarginsGuide.trailingAnchor, priority: preferredPriority) ] case .vertical: - return [ + [ accessoryView.topAnchor.constraint(equalTo: layoutMarginsGuide.topAnchor, priority: preferredPriority), accessoryView.bottomAnchor.constraint(equalTo: layoutMarginsGuide.bottomAnchor, priority: preferredPriority) ] @@ -379,12 +371,12 @@ public final class SwappingContainerView [NSLayoutConstraint] { switch axis { case .horizontal: - return [ + [ customView.leadingAnchor.constraint(equalTo: layoutMarginsGuide.leadingAnchor, priority: preferredPriority), customView.trailingAnchor.constraint(equalTo: layoutMarginsGuide.trailingAnchor, priority: preferredPriority) ] case .vertical: - return [ + [ customView.topAnchor.constraint(equalTo: layoutMarginsGuide.topAnchor, priority: preferredPriority), customView.bottomAnchor.constraint(equalTo: layoutMarginsGuide.bottomAnchor, priority: preferredPriority) ] @@ -394,16 +386,15 @@ public final class SwappingContainerView (accessory: [NSLayoutConstraint], customView: [NSLayoutConstraint]) { switch axis { case .horizontal: - return (accessory: [accessoryView.topAnchor.constraint(equalTo: layoutMarginsGuide.topAnchor, priority: preferredPriority), - accessoryView.bottomAnchor.constraint(equalTo: layoutMarginsGuide.bottomAnchor, priority: preferredPriority)], - customView: [customView.topAnchor.constraint(equalTo: layoutMarginsGuide.topAnchor, priority: preferredPriority), - customView.bottomAnchor.constraint(equalTo: layoutMarginsGuide.bottomAnchor, priority: preferredPriority)]) + (accessory: [accessoryView.topAnchor.constraint(equalTo: layoutMarginsGuide.topAnchor, priority: preferredPriority), + accessoryView.bottomAnchor.constraint(equalTo: layoutMarginsGuide.bottomAnchor, priority: preferredPriority)], + customView: [customView.topAnchor.constraint(equalTo: layoutMarginsGuide.topAnchor, priority: preferredPriority), + customView.bottomAnchor.constraint(equalTo: layoutMarginsGuide.bottomAnchor, priority: preferredPriority)]) case .vertical: - return (accessory: [accessoryView.leadingAnchor.constraint(equalTo: layoutMarginsGuide.leadingAnchor, priority: preferredPriority), - accessoryView.trailingAnchor.constraint(equalTo: layoutMarginsGuide.trailingAnchor, priority: preferredPriority)], - customView: [customView.leadingAnchor.constraint(equalTo: layoutMarginsGuide.leadingAnchor, priority: preferredPriority), - customView.trailingAnchor.constraint(equalTo: layoutMarginsGuide.trailingAnchor, priority: preferredPriority)]) + (accessory: [accessoryView.leadingAnchor.constraint(equalTo: layoutMarginsGuide.leadingAnchor, priority: preferredPriority), + accessoryView.trailingAnchor.constraint(equalTo: layoutMarginsGuide.trailingAnchor, priority: preferredPriority)], + customView: [customView.leadingAnchor.constraint(equalTo: layoutMarginsGuide.leadingAnchor, priority: preferredPriority), + customView.trailingAnchor.constraint(equalTo: layoutMarginsGuide.trailingAnchor, priority: preferredPriority)]) } } - } diff --git a/Example/ChatLayout/AppDelegate.swift b/Example/ChatLayout/AppDelegate.swift index fa6afb80..2ff2ac1d 100644 --- a/Example/ChatLayout/AppDelegate.swift +++ b/Example/ChatLayout/AppDelegate.swift @@ -14,7 +14,6 @@ import UIKit @main class AppDelegate: UIResponder, UIApplicationDelegate { - var window: UIWindow? func application(_: UIApplication, didFinishLaunchingWithOptions _: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { diff --git a/Example/ChatLayout/Chat/Builder/ChatViewControllerBuilder.swift b/Example/ChatLayout/Chat/Builder/ChatViewControllerBuilder.swift index c0f68498..278b2fce 100644 --- a/Example/ChatLayout/Chat/Builder/ChatViewControllerBuilder.swift +++ b/Example/ChatLayout/Chat/Builder/ChatViewControllerBuilder.swift @@ -14,7 +14,6 @@ import Foundation import UIKit struct ChatViewControllerBuilder { - func build() -> UIViewController { let dataProvider = DefaultRandomDataProvider(receiverId: 0, usersIds: [1, 2, 3]) let messageController = DefaultChatController(dataProvider: dataProvider, userId: 0) @@ -33,5 +32,4 @@ struct ChatViewControllerBuilder { return messageViewController } - } diff --git a/Example/ChatLayout/Chat/Constants.swift b/Example/ChatLayout/Chat/Constants.swift index 4d01c9d8..83fc2789 100644 --- a/Example/ChatLayout/Chat/Constants.swift +++ b/Example/ChatLayout/Chat/Constants.swift @@ -14,11 +14,9 @@ import Foundation import UIKit struct Constants { - static let tailSize: CGFloat = 5 static let maxWidth: CGFloat = 0.65 private init() {} - } diff --git a/Example/ChatLayout/Chat/Controller/ChatController.swift b/Example/ChatLayout/Chat/Controller/ChatController.swift index e67190d6..206d6264 100644 --- a/Example/ChatLayout/Chat/Controller/ChatController.swift +++ b/Example/ChatLayout/Chat/Controller/ChatController.swift @@ -13,11 +13,9 @@ import Foundation protocol ChatController { - func loadInitialMessages(completion: @escaping ([Section]) -> Void) func loadPreviousMessages(completion: @escaping ([Section]) -> Void) func sendMessage(_ data: Message.Data, completion: @escaping ([Section]) -> Void) - } diff --git a/Example/ChatLayout/Chat/Controller/ChatControllerDelegate.swift b/Example/ChatLayout/Chat/Controller/ChatControllerDelegate.swift index 69deb189..b08acebb 100644 --- a/Example/ChatLayout/Chat/Controller/ChatControllerDelegate.swift +++ b/Example/ChatLayout/Chat/Controller/ChatControllerDelegate.swift @@ -13,7 +13,5 @@ import Foundation protocol ChatControllerDelegate: AnyObject { - func update(with sections: [Section], requiresIsolatedProcess: Bool) - } diff --git a/Example/ChatLayout/Chat/Controller/DefaultChatController.swift b/Example/ChatLayout/Chat/Controller/DefaultChatController.swift index 8cd86729..8858c69a 100644 --- a/Example/ChatLayout/Chat/Controller/DefaultChatController.swift +++ b/Example/ChatLayout/Chat/Controller/DefaultChatController.swift @@ -14,7 +14,6 @@ import ChatLayout import Foundation final class DefaultChatController: ChatController { - weak var delegate: ChatControllerDelegate? private let dataProvider: RandomDataProvider @@ -154,17 +153,16 @@ final class DefaultChatController: ChatController { completion([Section(id: 0, title: "Loading...", cells: Array(cells))]) } } - } private func convert(_ data: Message.Data) -> RawMessage.Data { switch data { case let .url(url, isLocallyStored: _): - return .url(url) + .url(url) case let .image(source, isLocallyStored: _): - return .image(source) + .image(source) case let .text(text): - return .text(text) + .text(text) } } @@ -182,9 +180,9 @@ final class DefaultChatController: ChatController { func isPresentLocally(_ source: ImageMessageSource) -> Bool { switch source { case .image: - return true + true case let .imageURL(url): - return imageCache.isEntityCached(for: CacheableImageKey(url: url)) + imageCache.isEntityCached(for: CacheableImageKey(url: url)) } } return .image(source, isLocallyStored: isPresentLocally(source)) @@ -198,11 +196,9 @@ final class DefaultChatController: ChatController { self.delegate?.update(with: sections, requiresIsolatedProcess: requiresIsolatedProcess) } } - } extension DefaultChatController: RandomDataProviderDelegate { - func received(messages: [RawMessage]) { appendConvertingToMessages(messages) markAllMessagesAsReceived { @@ -290,22 +286,17 @@ extension DefaultChatController: RandomDataProviderDelegate { } } } - } extension DefaultChatController: ReloadDelegate { - func reloadMessage(with id: UUID) { repopulateMessages() } - } extension DefaultChatController: EditingAccessoryControllerDelegate { - func deleteMessage(with id: UUID) { messages = Array(messages.filter { $0.id != id }) repopulateMessages(requiresIsolatedProcess: true) } - } diff --git a/Example/ChatLayout/Chat/Controller/Helpers/DifferenceKit+Extension.swift b/Example/ChatLayout/Chat/Controller/Helpers/DifferenceKit+Extension.swift index 83fb8bdc..f21e5cd3 100644 --- a/Example/ChatLayout/Chat/Controller/Helpers/DifferenceKit+Extension.swift +++ b/Example/ChatLayout/Chat/Controller/Helpers/DifferenceKit+Extension.swift @@ -16,7 +16,6 @@ import Foundation import UIKit public extension UICollectionView { - func reload( using stagedChangeset: StagedChangeset, interrupt: ((Changeset) -> Bool)? = nil, @@ -110,11 +109,9 @@ public extension UICollectionView { completion!(true) } } - } extension StagedChangeset { - // DifferenceKit splits different type of actions into the different change sets to avoid the limitations of UICollectionView // But it may lead to the situations that `UICollectionViewLayout` doesnt know what change will happen next within the single portion // of changes. As we know that at least insertions and deletions can be processed together, we fix that in the StagedChangeset we got from @@ -129,5 +126,4 @@ extension StagedChangeset { } return self } - } diff --git a/Example/ChatLayout/Chat/Controller/Helpers/SetActor.swift b/Example/ChatLayout/Chat/Controller/Helpers/SetActor.swift index 7c3a942f..03cbd62c 100644 --- a/Example/ChatLayout/Chat/Controller/Helpers/SetActor.swift +++ b/Example/ChatLayout/Chat/Controller/Helpers/SetActor.swift @@ -13,9 +13,7 @@ import Foundation public final class SetActor { - public enum Action { - case onEmpty case onChange @@ -23,19 +21,15 @@ public final class SetActor { case onInsertion(_ option: Option) case onRemoval(_ option: Option) - } public enum ExecutionType { - case once case eternal - } public final class Reaction { - public let type: ReactionType public let action: Action @@ -50,7 +44,6 @@ public final class SetActor { self.executionType = executionType self.actionBlock = actionBlock } - } public var options: Option { @@ -147,15 +140,11 @@ public final class SetActor { } } } - } - } public extension SetActor where ReactionType: Equatable { - func removeAllReactions(_ type: ReactionType) { reactions.removeAll(where: { $0.type == type }) } - } diff --git a/Example/ChatLayout/Chat/Controller/Image Loader/CachingImageLoader.swift b/Example/ChatLayout/Chat/Controller/Image Loader/CachingImageLoader.swift index dea6d316..b2f006e4 100644 --- a/Example/ChatLayout/Chat/Controller/Image Loader/CachingImageLoader.swift +++ b/Example/ChatLayout/Chat/Controller/Image Loader/CachingImageLoader.swift @@ -14,7 +14,6 @@ import Foundation import UIKit public struct CachingImageLoader: ImageLoader where C.CachingKey == CacheableImageKey, C.Entity == UIImage { - private let cache: C private let loader: ImageLoader @@ -43,5 +42,4 @@ public struct CachingImageLoader: ImageLoader where C.C }) }) } - } diff --git a/Example/ChatLayout/Chat/Controller/Image Loader/DefaultImageLoader.swift b/Example/ChatLayout/Chat/Controller/Image Loader/DefaultImageLoader.swift index 7b7fc16e..73336ae4 100644 --- a/Example/ChatLayout/Chat/Controller/Image Loader/DefaultImageLoader.swift +++ b/Example/ChatLayout/Chat/Controller/Image Loader/DefaultImageLoader.swift @@ -14,7 +14,6 @@ import Foundation import UIKit public struct DefaultImageLoader: ImageLoader { - public enum ImageError: Error { case unknown case corruptedData @@ -50,5 +49,4 @@ public struct DefaultImageLoader: ImageLoader { }) sessionDataTask.resume() } - } diff --git a/Example/ChatLayout/Chat/Controller/Image Loader/ImageLoader.swift b/Example/ChatLayout/Chat/Controller/Image Loader/ImageLoader.swift index 05e81121..455fddd7 100644 --- a/Example/ChatLayout/Chat/Controller/Image Loader/ImageLoader.swift +++ b/Example/ChatLayout/Chat/Controller/Image Loader/ImageLoader.swift @@ -14,7 +14,5 @@ import Foundation import UIKit public protocol ImageLoader { - func loadImage(from url: URL, completion: @escaping (Result) -> Void) - } diff --git a/Example/ChatLayout/Chat/Controller/Image Loader/ImageMessageSource.swift b/Example/ChatLayout/Chat/Controller/Image Loader/ImageMessageSource.swift index 0f3a031f..9f7a364c 100644 --- a/Example/ChatLayout/Chat/Controller/Image Loader/ImageMessageSource.swift +++ b/Example/ChatLayout/Chat/Controller/Image Loader/ImageMessageSource.swift @@ -14,9 +14,6 @@ import Foundation import UIKit enum ImageMessageSource: Hashable { - case image(UIImage) - case imageURL(URL) - } diff --git a/Example/ChatLayout/Chat/Controller/Keyboard/KeyboardInfo.swift b/Example/ChatLayout/Chat/Controller/Keyboard/KeyboardInfo.swift index a8b6e746..bd20e6ca 100644 --- a/Example/ChatLayout/Chat/Controller/Keyboard/KeyboardInfo.swift +++ b/Example/ChatLayout/Chat/Controller/Keyboard/KeyboardInfo.swift @@ -14,7 +14,6 @@ import Foundation import UIKit struct KeyboardInfo: Equatable { - let animationDuration: Double let animationCurve: UIView.AnimationCurve @@ -43,5 +42,4 @@ struct KeyboardInfo: Equatable { frameBegin = keyboardFrameBegin frameEnd = keyboardFrameEnd } - } diff --git a/Example/ChatLayout/Chat/Controller/Keyboard/KeyboardListener.swift b/Example/ChatLayout/Chat/Controller/Keyboard/KeyboardListener.swift index 0e7b5591..a9b3ecfc 100644 --- a/Example/ChatLayout/Chat/Controller/Keyboard/KeyboardListener.swift +++ b/Example/ChatLayout/Chat/Controller/Keyboard/KeyboardListener.swift @@ -14,7 +14,6 @@ import Foundation import UIKit final class KeyboardListener { - static let shared = KeyboardListener() private(set) var isKeyboardVisible: Bool = false @@ -31,7 +30,8 @@ final class KeyboardListener { subscribeToKeyboardNotifications() } - @objc private func keyboardWillShow(_ notification: Notification) { + @objc + private func keyboardWillShow(_ notification: Notification) { guard let info = KeyboardInfo(notification) else { return } @@ -43,7 +43,8 @@ final class KeyboardListener { } } - @objc private func keyboardWillChangeFrame(_ notification: Notification) { + @objc + private func keyboardWillChangeFrame(_ notification: Notification) { guard let info = KeyboardInfo(notification) else { return } @@ -53,7 +54,8 @@ final class KeyboardListener { } } - @objc private func keyboardDidChangeFrame(_ notification: Notification) { + @objc + private func keyboardDidChangeFrame(_ notification: Notification) { guard let info = KeyboardInfo(notification) else { return } @@ -63,7 +65,8 @@ final class KeyboardListener { } } - @objc private func keyboardDidShow(_ notification: Notification) { + @objc + private func keyboardDidShow(_ notification: Notification) { guard let info = KeyboardInfo(notification) else { return } @@ -73,7 +76,8 @@ final class KeyboardListener { } } - @objc private func keyboardWillHide(_ notification: Notification) { + @objc + private func keyboardWillHide(_ notification: Notification) { guard let info = KeyboardInfo(notification) else { return } @@ -83,7 +87,8 @@ final class KeyboardListener { } } - @objc private func keyboardDidHide(_ notification: Notification) { + @objc + private func keyboardDidHide(_ notification: Notification) { guard let info = KeyboardInfo(notification) else { return } @@ -120,5 +125,4 @@ final class KeyboardListener { name: UIResponder.keyboardDidChangeFrameNotification, object: nil) } - } diff --git a/Example/ChatLayout/Chat/Controller/Keyboard/KeyboardListenerDelegate.swift b/Example/ChatLayout/Chat/Controller/Keyboard/KeyboardListenerDelegate.swift index d91b2838..bd56fc22 100644 --- a/Example/ChatLayout/Chat/Controller/Keyboard/KeyboardListenerDelegate.swift +++ b/Example/ChatLayout/Chat/Controller/Keyboard/KeyboardListenerDelegate.swift @@ -13,23 +13,19 @@ import Foundation protocol KeyboardListenerDelegate: AnyObject { - func keyboardWillShow(info: KeyboardInfo) func keyboardDidShow(info: KeyboardInfo) func keyboardWillHide(info: KeyboardInfo) func keyboardDidHide(info: KeyboardInfo) func keyboardWillChangeFrame(info: KeyboardInfo) func keyboardDidChangeFrame(info: KeyboardInfo) - } extension KeyboardListenerDelegate { - func keyboardWillShow(info: KeyboardInfo) {} func keyboardDidShow(info: KeyboardInfo) {} func keyboardWillHide(info: KeyboardInfo) {} func keyboardDidHide(info: KeyboardInfo) {} func keyboardWillChangeFrame(info: KeyboardInfo) {} func keyboardDidChangeFrame(info: KeyboardInfo) {} - } diff --git a/Example/ChatLayout/Chat/Model/Caches.swift b/Example/ChatLayout/Chat/Model/Caches.swift index 0dd4c5e1..5a2ab149 100644 --- a/Example/ChatLayout/Chat/Model/Caches.swift +++ b/Example/ChatLayout/Chat/Model/Caches.swift @@ -16,13 +16,13 @@ let loader = CachingImageLoader(cache: imageCache, loader: DefaultImageLoader()) @available(iOS 13, *) var metadataCache = IterativeCache(mainCache: MetaDataCache(cache: MemoryDataCache()), - backupCache: MetaDataCache(cache: PersistentDataCache(cacheFileExtension: "metadataCache"))) + backupCache: MetaDataCache(cache: PersistentDataCache(cacheFileExtension: "metadataCache"))) let imageCache = IterativeCache(mainCache: ImageForUrlCache(cache: MemoryDataCache()), - backupCache: ImageForUrlCache(cache: PersistentDataCache())) + backupCache: ImageForUrlCache(cache: PersistentDataCache())) //// Uncomment to reload dynamic content on every start. -//@available(iOS 13, *) -//var metadataCache = MetaDataCache(cache: MemoryDataCache()) +// @available(iOS 13, *) +// var metadataCache = MetaDataCache(cache: MemoryDataCache()) // -//let imageCache = ImageForUrlCache(cache: MemoryDataCache()) +// let imageCache = ImageForUrlCache(cache: MemoryDataCache()) diff --git a/Example/ChatLayout/Chat/Model/Caching/AsyncKeyValueCaching.swift b/Example/ChatLayout/Chat/Model/Caching/AsyncKeyValueCaching.swift index ec70749d..3de4e388 100644 --- a/Example/ChatLayout/Chat/Model/Caching/AsyncKeyValueCaching.swift +++ b/Example/ChatLayout/Chat/Model/Caching/AsyncKeyValueCaching.swift @@ -13,17 +13,14 @@ import Foundation public protocol AsyncKeyValueCaching: KeyValueCaching { - associatedtype CachingKey associatedtype Entity func getEntity(for key: CachingKey, completion: @escaping (Result) -> Void) - } public extension AsyncKeyValueCaching { - func getEntity(for key: CachingKey, completion: @escaping (Result) -> Void) { DispatchQueue.global().async { do { @@ -38,5 +35,4 @@ public extension AsyncKeyValueCaching { } } } - } diff --git a/Example/ChatLayout/Chat/Model/Caching/CacheError.swift b/Example/ChatLayout/Chat/Model/Caching/CacheError.swift index 1a4067f5..5335d8ae 100644 --- a/Example/ChatLayout/Chat/Model/Caching/CacheError.swift +++ b/Example/ChatLayout/Chat/Model/Caching/CacheError.swift @@ -13,11 +13,9 @@ import Foundation public enum CacheError: Error { - case notFound case invalidData case custom(Error) - } diff --git a/Example/ChatLayout/Chat/Model/Caching/Data/IterativeCache.swift b/Example/ChatLayout/Chat/Model/Caching/Data/IterativeCache.swift index 4f46a92a..cf55e1ab 100644 --- a/Example/ChatLayout/Chat/Model/Caching/Data/IterativeCache.swift +++ b/Example/ChatLayout/Chat/Model/Caching/Data/IterativeCache.swift @@ -16,7 +16,6 @@ import UIKit public final class IterativeCache: AsyncKeyValueCaching where FastCache.CachingKey == SlowCache.CachingKey, FastCache.Entity == SlowCache.Entity { - public let mainCache: FastCache public let backupCache: SlowCache @@ -32,9 +31,9 @@ public final class IterativeCache FastCache.Entity { if let image = try? mainCache.getEntity(for: key) { - return image + image } else { - return try backupCache.getEntity(for: key) + try backupCache.getEntity(for: key) } } @@ -63,5 +62,4 @@ public final class IterativeCache: AsyncKeyValueCaching { - private final class WrappedKey: NSObject { - let key: CachingKey init(_ key: CachingKey) { @@ -33,17 +31,14 @@ public final class MemoryDataCache: AsyncKeyValueCaching { return value.key == key } - } private final class Entry { - let data: Data init(_ data: Data) { self.data = data } - } private let cache = NSCache() @@ -83,5 +78,4 @@ public final class MemoryDataCache: AsyncKeyValueCaching { public func store(entity: Data, for key: CachingKey) { cache.setObject(Entry(entity), forKey: WrappedKey(key), cost: Int(Date().timeIntervalSince1970)) } - } diff --git a/Example/ChatLayout/Chat/Model/Caching/Data/PersistentDataCache.swift b/Example/ChatLayout/Chat/Model/Caching/Data/PersistentDataCache.swift index a63ec543..35255594 100644 --- a/Example/ChatLayout/Chat/Model/Caching/Data/PersistentDataCache.swift +++ b/Example/ChatLayout/Chat/Model/Caching/Data/PersistentDataCache.swift @@ -15,7 +15,6 @@ import Foundation private let expirationFileAttribute = "saks.persistent-auto-purging-cache.expiration" class PersistentDataCache: AsyncKeyValueCaching { - private let fileManager = FileManager() private let persistencePath: String @@ -128,5 +127,4 @@ class PersistentDataCache: AsyncKeyValueCachi return files } - } diff --git a/Example/ChatLayout/Chat/Model/Caching/Data/PersistentlyCacheable.swift b/Example/ChatLayout/Chat/Model/Caching/Data/PersistentlyCacheable.swift index 39b68d49..256040d2 100644 --- a/Example/ChatLayout/Chat/Model/Caching/Data/PersistentlyCacheable.swift +++ b/Example/ChatLayout/Chat/Model/Caching/Data/PersistentlyCacheable.swift @@ -13,7 +13,5 @@ import Foundation protocol PersistentlyCacheable { - var persistentIdentifier: String { get } - } diff --git a/Example/ChatLayout/Chat/Model/Caching/Image/CacheableImageKey.swift b/Example/ChatLayout/Chat/Model/Caching/Image/CacheableImageKey.swift index 0694d5b4..3414cd29 100644 --- a/Example/ChatLayout/Chat/Model/Caching/Image/CacheableImageKey.swift +++ b/Example/ChatLayout/Chat/Model/Caching/Image/CacheableImageKey.swift @@ -14,11 +14,9 @@ import Foundation import UIKit public struct CacheableImageKey: Hashable, PersistentlyCacheable { - public let url: URL var persistentIdentifier: String { url.absoluteString.addingPercentEncoding(withAllowedCharacters: .alphanumerics) ?? url.absoluteString } - } diff --git a/Example/ChatLayout/Chat/Model/Caching/Image/ImageForUrlCache.swift b/Example/ChatLayout/Chat/Model/Caching/Image/ImageForUrlCache.swift index bf605d30..3eb928c0 100644 --- a/Example/ChatLayout/Chat/Model/Caching/Image/ImageForUrlCache.swift +++ b/Example/ChatLayout/Chat/Model/Caching/Image/ImageForUrlCache.swift @@ -14,7 +14,6 @@ import Foundation import UIKit public final class ImageForUrlCache: AsyncKeyValueCaching where Cache.CachingKey: Hashable, Cache.Entity == Data { - private let cache: Cache public init(cache: Cache) { @@ -62,5 +61,4 @@ public final class ImageForUrlCache: AsyncKeyValueC } try cache.store(entity: data, for: key) } - } diff --git a/Example/ChatLayout/Chat/Model/Caching/KeyValueCaching.swift b/Example/ChatLayout/Chat/Model/Caching/KeyValueCaching.swift index 2dd589d0..150979e6 100644 --- a/Example/ChatLayout/Chat/Model/Caching/KeyValueCaching.swift +++ b/Example/ChatLayout/Chat/Model/Caching/KeyValueCaching.swift @@ -13,7 +13,6 @@ import Foundation public protocol KeyValueCaching { - associatedtype CachingKey associatedtype Entity @@ -23,5 +22,4 @@ public protocol KeyValueCaching { func getEntity(for key: CachingKey) throws -> Entity func store(entity: Entity, for key: CachingKey) throws - } diff --git a/Example/ChatLayout/Chat/Model/Caching/Metadata/MetaDataCache.swift b/Example/ChatLayout/Chat/Model/Caching/Metadata/MetaDataCache.swift index 2497164f..2be0e7dc 100644 --- a/Example/ChatLayout/Chat/Model/Caching/Metadata/MetaDataCache.swift +++ b/Example/ChatLayout/Chat/Model/Caching/Metadata/MetaDataCache.swift @@ -16,7 +16,6 @@ import UIKit @available(iOS 13, *) final class MetaDataCache: AsyncKeyValueCaching where Cache.CachingKey == URL, Cache.Entity == Data { - private var cache: Cache init(cache: Cache) { @@ -56,16 +55,13 @@ final class MetaDataCache: AsyncKeyValueCaching whe // swiftlint:enable force_try try cache.store(entity: codedData, for: key) } - } extension URL: PersistentlyCacheable { - var persistentIdentifier: String { guard let percentEncoding = absoluteString.addingPercentEncoding(withAllowedCharacters: .alphanumerics) else { fatalError() } return percentEncoding } - } diff --git a/Example/ChatLayout/Chat/Model/ChatDateFormatter.swift b/Example/ChatLayout/Chat/Model/ChatDateFormatter.swift index de48cd49..60fa0748 100644 --- a/Example/ChatLayout/Chat/Model/ChatDateFormatter.swift +++ b/Example/ChatLayout/Chat/Model/ChatDateFormatter.swift @@ -13,7 +13,6 @@ import Foundation public final class ChatDateFormatter { - // MARK: - Properties public static let shared = ChatDateFormatter() @@ -50,11 +49,9 @@ public final class ChatDateFormatter { formatter.dateFormat = "MMM d, yyyy, hh:mm" } } - } public final class MessageDateFormatter { - public static let shared = MessageDateFormatter() private let formatter = DateFormatter() @@ -73,5 +70,4 @@ public final class MessageDateFormatter { let dateString = string(from: date) return NSAttributedString(string: dateString, attributes: attributes) } - } diff --git a/Example/ChatLayout/Chat/Model/Data Objects/Cell.swift b/Example/ChatLayout/Chat/Model/Data Objects/Cell.swift index 23ae4024..ec8678eb 100644 --- a/Example/ChatLayout/Chat/Model/Data Objects/Cell.swift +++ b/Example/ChatLayout/Chat/Model/Data Objects/Cell.swift @@ -16,7 +16,6 @@ import Foundation import UIKit enum Cell: Hashable { - enum BubbleType { case normal case tailed @@ -33,35 +32,32 @@ enum Cell: Hashable { var alignment: ChatItemAlignment { switch self { case let .message(message, _): - return message.type == .incoming ? .leading : .trailing + message.type == .incoming ? .leading : .trailing case .typingIndicator: - return .leading + .leading case let .messageGroup(group): - return group.type == .incoming ? .leading : .trailing + group.type == .incoming ? .leading : .trailing case .date: - return .center + .center } } - } extension Cell: Differentiable { - public var differenceIdentifier: Int { switch self { case let .message(message, _): - return message.differenceIdentifier + message.differenceIdentifier case .typingIndicator: - return hashValue + hashValue case let .messageGroup(group): - return group.differenceIdentifier + group.differenceIdentifier case let .date(group): - return group.differenceIdentifier + group.differenceIdentifier } } public func isContentEqual(to source: Cell) -> Bool { self == source } - } diff --git a/Example/ChatLayout/Chat/Model/Data Objects/Message.swift b/Example/ChatLayout/Chat/Model/Data Objects/Message.swift index 9c0b6ac5..80a740da 100644 --- a/Example/ChatLayout/Chat/Model/Data Objects/Message.swift +++ b/Example/ChatLayout/Chat/Model/Data Objects/Message.swift @@ -15,7 +15,6 @@ import DifferenceKit import Foundation enum MessageType: Hashable { - case incoming case outgoing @@ -23,29 +22,23 @@ enum MessageType: Hashable { var isIncoming: Bool { self == .incoming } - } enum MessageStatus: Hashable { - case sent case received case read - } extension ChatItemAlignment { - var isIncoming: Bool { self == .leading } - } struct DateGroup: Hashable { - var id: UUID var date: Date @@ -58,11 +51,9 @@ struct DateGroup: Hashable { self.id = id self.date = date } - } extension DateGroup: Differentiable { - public var differenceIdentifier: Int { hashValue } @@ -70,11 +61,9 @@ extension DateGroup: Differentiable { public func isContentEqual(to source: DateGroup) -> Bool { self == source } - } struct MessageGroup: Hashable { - var id: UUID var title: String @@ -86,11 +75,9 @@ struct MessageGroup: Hashable { self.title = title self.type = type } - } extension MessageGroup: Differentiable { - public var differenceIdentifier: Int { hashValue } @@ -98,19 +85,15 @@ extension MessageGroup: Differentiable { public func isContentEqual(to source: MessageGroup) -> Bool { self == source } - } struct Message: Hashable { - enum Data: Hashable { - case text(String) case url(URL, isLocallyStored: Bool) case image(ImageMessageSource, isLocallyStored: Bool) - } var id: UUID @@ -124,11 +107,9 @@ struct Message: Hashable { var type: MessageType var status: MessageStatus = .sent - } extension Message: Differentiable { - public var differenceIdentifier: Int { id.hashValue } @@ -136,5 +117,4 @@ extension Message: Differentiable { public func isContentEqual(to source: Message) -> Bool { self == source } - } diff --git a/Example/ChatLayout/Chat/Model/Data Objects/RawMessage.swift b/Example/ChatLayout/Chat/Model/Data Objects/RawMessage.swift index d4c2f76c..b67b0166 100644 --- a/Example/ChatLayout/Chat/Model/Data Objects/RawMessage.swift +++ b/Example/ChatLayout/Chat/Model/Data Objects/RawMessage.swift @@ -14,15 +14,12 @@ import Foundation import UIKit struct RawMessage: Hashable { - enum Data: Hashable { - case text(String) case url(URL) case image(ImageMessageSource) - } var id: UUID @@ -34,5 +31,4 @@ struct RawMessage: Hashable { var userId: Int var status: MessageStatus = .sent - } diff --git a/Example/ChatLayout/Chat/Model/Data Objects/Section.swift b/Example/ChatLayout/Chat/Model/Data Objects/Section.swift index 5f8b8b56..84982f36 100644 --- a/Example/ChatLayout/Chat/Model/Data Objects/Section.swift +++ b/Example/ChatLayout/Chat/Model/Data Objects/Section.swift @@ -14,17 +14,14 @@ import DifferenceKit import Foundation struct Section: Hashable { - var id: Int var title: String var cells: [Cell] - } extension Section: DifferentiableSection { - public var differenceIdentifier: Int { id } @@ -40,5 +37,4 @@ extension Section: DifferentiableSection { public init(source: Section, elements: C) where C.Element == Cell { self.init(id: source.id, title: source.title, cells: Array(elements)) } - } diff --git a/Example/ChatLayout/Chat/Model/Data Objects/TypingState.swift b/Example/ChatLayout/Chat/Model/Data Objects/TypingState.swift index d56850d8..61fbbd37 100644 --- a/Example/ChatLayout/Chat/Model/Data Objects/TypingState.swift +++ b/Example/ChatLayout/Chat/Model/Data Objects/TypingState.swift @@ -13,9 +13,7 @@ import Foundation enum TypingState { - case idle case typing - } diff --git a/Example/ChatLayout/Chat/Model/Data Objects/User.swift b/Example/ChatLayout/Chat/Model/Data Objects/User.swift index c33daa45..7b6360b7 100644 --- a/Example/ChatLayout/Chat/Model/Data Objects/User.swift +++ b/Example/ChatLayout/Chat/Model/Data Objects/User.swift @@ -15,24 +15,22 @@ import Foundation import UIKit struct User: Hashable { - var id: Int var name: String { switch id { case 0: - return "Chat Layout" + "Chat Layout" case 1: - return "Eugene Kazaev" + "Eugene Kazaev" case 2: - return "Cathal Murphy" + "Cathal Murphy" case 3: - return "Aliaksandra Mikhailouskaya" + "Aliaksandra Mikhailouskaya" default: fatalError() } } - } extension User: Differentiable {} diff --git a/Example/ChatLayout/Chat/Model/DefaultRandomDataProvider.swift b/Example/ChatLayout/Chat/Model/DefaultRandomDataProvider.swift index fc191210..ef8cdc92 100644 --- a/Example/ChatLayout/Chat/Model/DefaultRandomDataProvider.swift +++ b/Example/ChatLayout/Chat/Model/DefaultRandomDataProvider.swift @@ -14,7 +14,6 @@ import Foundation import UIKit protocol RandomDataProviderDelegate: AnyObject { - func received(messages: [RawMessage]) func typingStateChanged(to state: TypingState) @@ -22,21 +21,17 @@ protocol RandomDataProviderDelegate: AnyObject { func lastReadIdChanged(to id: UUID) func lastReceivedIdChanged(to id: UUID) - } protocol RandomDataProvider { - func loadInitialMessages(completion: @escaping ([RawMessage]) -> Void) func loadPreviousMessages(completion: @escaping ([RawMessage]) -> Void) func stop() - } final class DefaultRandomDataProvider: RandomDataProvider { - weak var delegate: RandomDataProviderDelegate? private var messageTimer: Timer? @@ -211,5 +206,4 @@ final class DefaultRandomDataProvider: RandomDataProvider { } return messages } - } diff --git a/Example/ChatLayout/Chat/Model/TextGenerator.swift b/Example/ChatLayout/Chat/Model/TextGenerator.swift index 14eba480..55971dfb 100644 --- a/Example/ChatLayout/Chat/Model/TextGenerator.swift +++ b/Example/ChatLayout/Chat/Model/TextGenerator.swift @@ -13,7 +13,6 @@ import Foundation public class TextGenerator { - private static let words = [ "alias", "consequatur", "aut", "perferendis", "sit", "voluptatem", "accusantium", "doloremque", "aperiam", "eaque", "ipsa", "quae", "ab", @@ -63,5 +62,4 @@ public class TextGenerator { result.replaceSubrange(result.startIndex...result.startIndex, with: String(result[result.startIndex]).capitalized) return result + "." } - } diff --git a/Example/ChatLayout/Chat/View/Avatar View/AvatarPlaceholderView.swift b/Example/ChatLayout/Chat/View/Avatar View/AvatarPlaceholderView.swift index 94594fdd..ecf6fb96 100644 --- a/Example/ChatLayout/Chat/View/Avatar View/AvatarPlaceholderView.swift +++ b/Example/ChatLayout/Chat/View/Avatar View/AvatarPlaceholderView.swift @@ -15,7 +15,6 @@ import Foundation import UIKit final class AvatarPlaceholderView: UIView, StaticViewFactory { - override init(frame: CGRect) { super.init(frame: frame) setupSubviews() @@ -35,5 +34,4 @@ final class AvatarPlaceholderView: UIView, StaticViewFactory { constraint.isActive = true heightAnchor.constraint(equalTo: widthAnchor, multiplier: 1).isActive = true } - } diff --git a/Example/ChatLayout/Chat/View/Avatar View/AvatarView.swift b/Example/ChatLayout/Chat/View/Avatar View/AvatarView.swift index 5cdeaa29..a7e21551 100644 --- a/Example/ChatLayout/Chat/View/Avatar View/AvatarView.swift +++ b/Example/ChatLayout/Chat/View/Avatar View/AvatarView.swift @@ -16,13 +16,10 @@ import UIKit // Just to visually test `ChatLayout.supportSelfSizingInvalidation` protocol AvatarViewDelegate: AnyObject { - func avatarTapped() - } final class AvatarView: UIView, StaticViewFactory { - weak var delegate: AvatarViewDelegate? private lazy var circleImageView = RoundedCornersContainerView(frame: bounds) @@ -78,8 +75,8 @@ final class AvatarView: UIView, StaticViewFactory { gestureRecogniser.addTarget(self, action: #selector(avatarTapped)) } - @objc private func avatarTapped() { + @objc + private func avatarTapped() { delegate?.avatarTapped() } - } diff --git a/Example/ChatLayout/Chat/View/Avatar View/AvatarViewController.swift b/Example/ChatLayout/Chat/View/Avatar View/AvatarViewController.swift index c71299f6..d7948585 100644 --- a/Example/ChatLayout/Chat/View/Avatar View/AvatarViewController.swift +++ b/Example/ChatLayout/Chat/View/Avatar View/AvatarViewController.swift @@ -14,7 +14,6 @@ import Foundation import UIKit final class AvatarViewController { - var image: UIImage? { guard bubble == .tailed else { return nil @@ -47,5 +46,4 @@ final class AvatarViewController { self.user = user self.bubble = bubble } - } diff --git a/Example/ChatLayout/Chat/View/ChatViewController.swift b/Example/ChatLayout/Chat/View/ChatViewController.swift index f8932ea9..a2997bbb 100644 --- a/Example/ChatLayout/Chat/View/ChatViewController.swift +++ b/Example/ChatLayout/Chat/View/ChatViewController.swift @@ -26,7 +26,6 @@ let enableSelfSizingSupport = false let enableReconfigure = false final class ChatViewController: UIViewController { - private enum ReactionTypes { case delayedUpdate } @@ -177,7 +176,6 @@ final class ChatViewController: UIViewController { KeyboardListener.shared.add(delegate: self) collectionView.addGestureRecognizer(panGesture) - } override func viewWillAppear(_ animated: Bool) { @@ -215,7 +213,8 @@ final class ChatViewController: UIViewController { super.viewWillTransition(to: size, with: coordinator) } - @objc private func showHideKeyboard() { + @objc + private func showHideKeyboard() { if inputBarView.inputTextView.isFirstResponder { navigationItem.leftBarButtonItem?.title = "Show Keyboard" inputBarView.inputTextView.resignFirstResponder() @@ -225,7 +224,8 @@ final class ChatViewController: UIViewController { } } - @objc private func setEditNotEdit() { + @objc + private func setEditNotEdit() { isEditing = !isEditing editNotifier.setIsEditing(isEditing, duration: .animated(duration: 0.25)) navigationItem.rightBarButtonItem?.title = isEditing ? "Done" : "Edit" @@ -255,7 +255,6 @@ final class ChatViewController: UIViewController { } extension ChatViewController: UIScrollViewDelegate { - public func scrollViewShouldScrollToTop(_ scrollView: UIScrollView) -> Bool { guard scrollView.contentSize.height > 0, !currentInterfaceActions.options.contains(.showingAccessory), @@ -362,11 +361,9 @@ extension ChatViewController: UIScrollViewDelegate { }) } } - } extension ChatViewController: UICollectionViewDelegate { - @available(iOS 13.0, *) private func preview(for configuration: UIContextMenuConfiguration) -> UITargetedPreview? { guard let identifier = configuration.identifier as? String else { @@ -452,11 +449,9 @@ extension ChatViewController: UICollectionViewDelegate { self.currentInterfaceActions.options.remove(.showingPreview) } } - } extension ChatViewController: ChatControllerDelegate { - func update(with sections: [Section], requiresIsolatedProcess: Bool) { processUpdates(with: sections, animated: true, requiresIsolatedProcess: requiresIsolatedProcess) } @@ -532,12 +527,11 @@ extension ChatViewController: ChatControllerDelegate { } } } - } extension ChatViewController: UIGestureRecognizerDelegate { - - @objc private func handleRevealPan(_ gesture: UIPanGestureRecognizer) { + @objc + private func handleRevealPan(_ gesture: UIPanGestureRecognizer) { guard let collectionView = gesture.view as? UICollectionView, !editNotifier.isEditing else { currentInterfaceActions.options.remove(.showingAccessory) @@ -566,7 +560,9 @@ extension ChatViewController: UIGestureRecognizerDelegate { private func updateTransforms(in collectionView: UICollectionView, transform: CGAffineTransform? = nil) { collectionView.indexPathsForVisibleItems.forEach { - guard let cell = collectionView.cellForItem(at: $0) else { return } + guard let cell = collectionView.cellForItem(at: $0) else { + return + } updateTransform(transform: transform, cell: cell, indexPath: $0) } } @@ -593,11 +589,9 @@ extension ChatViewController: UIGestureRecognizerDelegate { return true } - } extension ChatViewController: InputBarAccessoryViewDelegate { - public func inputBar(_ inputBar: InputBarAccessoryView, didChangeIntrinsicContentTo size: CGSize) { guard !currentInterfaceActions.options.contains(.sendingMessage) else { return @@ -626,11 +620,9 @@ extension ChatViewController: InputBarAccessoryViewDelegate { inputBar.inputTextView.text = String() inputBar.invalidatePlugins() } - } extension ChatViewController: KeyboardListenerDelegate { - func keyboardWillChangeFrame(info: KeyboardInfo) { guard !currentInterfaceActions.options.contains(.changingFrameSize), collectionView.contentInsetAdjustmentBehavior != .never, @@ -681,13 +673,10 @@ extension ChatViewController: KeyboardListenerDelegate { } currentInterfaceActions.options.remove(.changingKeyboardFrame) } - } extension ChatViewController: FPSCounterDelegate { - public func fpsCounter(_ counter: FPSCounter, didUpdateFramesPerSecond fps: Int) { fpsView.customView.text = "FPS: \(fps)" } - } diff --git a/Example/ChatLayout/Chat/View/Data Source/ChatCollectionDataSource.swift b/Example/ChatLayout/Chat/View/Data Source/ChatCollectionDataSource.swift index 3b5a9deb..5ac5efee 100644 --- a/Example/ChatLayout/Chat/View/Data Source/ChatCollectionDataSource.swift +++ b/Example/ChatLayout/Chat/View/Data Source/ChatCollectionDataSource.swift @@ -15,9 +15,7 @@ import Foundation import UIKit protocol ChatCollectionDataSource: UICollectionViewDataSource, ChatLayoutDelegate { - var sections: [Section] { get set } func prepare(with collectionView: UICollectionView) - } diff --git a/Example/ChatLayout/Chat/View/Data Source/DefaultChatCollectionDataSource.swift b/Example/ChatLayout/Chat/View/Data Source/DefaultChatCollectionDataSource.swift index 439b72c5..35d216a1 100644 --- a/Example/ChatLayout/Chat/View/Data Source/DefaultChatCollectionDataSource.swift +++ b/Example/ChatLayout/Chat/View/Data Source/DefaultChatCollectionDataSource.swift @@ -25,7 +25,6 @@ typealias TypingIndicatorCollectionCell = ContainerCollectionViewCell final class DefaultChatCollectionDataSource: NSObject, ChatCollectionDataSource { - private unowned var reloadDelegate: ReloadDelegate private unowned var editingDelegate: EditingAccessoryControllerDelegate @@ -242,11 +241,9 @@ final class DefaultChatCollectionDataSource: NSObject, ChatCollectionDataSource let bubbleController = BezierBubbleController(bubbleView: bubbleView, controllerProxy: contentBubbleController, type: messageType, bubbleType: bubbleType) return bubbleController } - } extension DefaultChatCollectionDataSource: UICollectionViewDataSource { - public func numberOfSections(in collectionView: UICollectionView) -> Int { sections.count } @@ -310,11 +307,9 @@ extension DefaultChatCollectionDataSource: UICollectionViewDataSource { fatalError() } } - } extension DefaultChatCollectionDataSource: ChatLayoutDelegate { - public func shouldPresentHeader(_ chatLayout: CollectionViewChatLayout, at sectionIndex: Int) -> Bool { true } @@ -349,7 +344,8 @@ extension DefaultChatCollectionDataSource: ChatLayoutDelegate { case .messageGroup: return .estimated(CGSize(width: min(85, chatLayout.layoutFrame.width / 3), height: 18)) } - case .footer, .header: + case .footer, + .header: return .auto } } @@ -365,7 +361,8 @@ extension DefaultChatCollectionDataSource: ChatLayoutDelegate { return .center case .message: return .fullWidth - case .messageGroup, .typingIndicator: + case .messageGroup, + .typingIndicator: return .leading } case .footer: diff --git a/Example/ChatLayout/Chat/View/Date Accessory View/DateAccessoryController.swift b/Example/ChatLayout/Chat/View/Date Accessory View/DateAccessoryController.swift index 4ddcdc26..9cace560 100644 --- a/Example/ChatLayout/Chat/View/Date Accessory View/DateAccessoryController.swift +++ b/Example/ChatLayout/Chat/View/Date Accessory View/DateAccessoryController.swift @@ -13,7 +13,6 @@ import Foundation final class DateAccessoryController { - private let date: Date let accessoryText: String @@ -22,5 +21,4 @@ final class DateAccessoryController { self.date = date accessoryText = MessageDateFormatter.shared.string(from: date) } - } diff --git a/Example/ChatLayout/Chat/View/Date Accessory View/DateAccessoryView.swift b/Example/ChatLayout/Chat/View/Date Accessory View/DateAccessoryView.swift index 7a3908c6..1d832ad4 100644 --- a/Example/ChatLayout/Chat/View/Date Accessory View/DateAccessoryView.swift +++ b/Example/ChatLayout/Chat/View/Date Accessory View/DateAccessoryView.swift @@ -14,7 +14,6 @@ import Foundation import UIKit final class DateAccessoryView: UIView { - private var accessoryView = UILabel() private var controller: DateAccessoryController? @@ -56,5 +55,4 @@ final class DateAccessoryView: UIView { accessoryView.font = UIFont.preferredFont(forTextStyle: .caption1) accessoryView.textColor = .gray } - } diff --git a/Example/ChatLayout/Chat/View/Editing Accessory View/EditingAccessoryController.swift b/Example/ChatLayout/Chat/View/Editing Accessory View/EditingAccessoryController.swift index ba900755..9b3b87c0 100644 --- a/Example/ChatLayout/Chat/View/Editing Accessory View/EditingAccessoryController.swift +++ b/Example/ChatLayout/Chat/View/Editing Accessory View/EditingAccessoryController.swift @@ -14,13 +14,10 @@ import Foundation import UIKit protocol EditingAccessoryControllerDelegate: AnyObject { - func deleteMessage(with id: UUID) - } final class EditingAccessoryController { - weak var delegate: EditingAccessoryControllerDelegate? weak var view: EditingAccessoryView? @@ -34,5 +31,4 @@ final class EditingAccessoryController { func deleteButtonTapped() { delegate?.deleteMessage(with: messageId) } - } diff --git a/Example/ChatLayout/Chat/View/Editing Accessory View/EditingAccessoryView.swift b/Example/ChatLayout/Chat/View/Editing Accessory View/EditingAccessoryView.swift index f2f8d709..db5a2a59 100644 --- a/Example/ChatLayout/Chat/View/Editing Accessory View/EditingAccessoryView.swift +++ b/Example/ChatLayout/Chat/View/Editing Accessory View/EditingAccessoryView.swift @@ -15,7 +15,6 @@ import Foundation import UIKit final class EditingAccessoryView: UIView, StaticViewFactory { - private lazy var button = UIButton(type: .system) override init(frame: CGRect) { @@ -52,14 +51,13 @@ final class EditingAccessoryView: UIView, StaticViewFactory { self.controller = controller } - @objc private func buttonTapped() { + @objc + private func buttonTapped() { controller?.deleteButtonTapped() } - } extension EditingAccessoryView: EditNotifierDelegate { - var isEditing: Bool { get { !isHidden @@ -84,5 +82,4 @@ extension EditingAccessoryView: EditNotifierDelegate { self.setNeedsLayout() } } - } diff --git a/Example/ChatLayout/Chat/View/Image View/ImageController.swift b/Example/ChatLayout/Chat/View/Image View/ImageController.swift index fea14d4e..aed21c87 100644 --- a/Example/ChatLayout/Chat/View/Image View/ImageController.swift +++ b/Example/ChatLayout/Chat/View/Image View/ImageController.swift @@ -14,7 +14,6 @@ import Foundation import UIKit final class ImageController { - weak var view: ImageView? { didSet { UIView.performWithoutAnimation { @@ -73,5 +72,4 @@ final class ImageController { view?.reloadData() } } - } diff --git a/Example/ChatLayout/Chat/View/Image View/ImageView.swift b/Example/ChatLayout/Chat/View/Image View/ImageView.swift index 3ea557dd..01175d43 100644 --- a/Example/ChatLayout/Chat/View/Image View/ImageView.swift +++ b/Example/ChatLayout/Chat/View/Image View/ImageView.swift @@ -15,7 +15,6 @@ import Foundation import UIKit final class ImageView: UIView, ContainerCollectionViewCellDelegate { - private lazy var stackView = UIStackView(frame: bounds) private lazy var loadingIndicator = UIActivityIndicatorView(style: .gray) @@ -157,5 +156,4 @@ final class ImageView: UIView, ContainerCollectionViewCellDelegate { } } } - } diff --git a/Example/ChatLayout/Chat/View/Image View/ImageViewState.swift b/Example/ChatLayout/Chat/View/Image View/ImageViewState.swift index 2ad9768b..a46bff84 100644 --- a/Example/ChatLayout/Chat/View/Image View/ImageViewState.swift +++ b/Example/ChatLayout/Chat/View/Image View/ImageViewState.swift @@ -14,9 +14,7 @@ import Foundation import UIKit enum ImageViewState { - case loading case image(UIImage) - } diff --git a/Example/ChatLayout/Chat/View/Other/BezierBubbleController.swift b/Example/ChatLayout/Chat/View/Other/BezierBubbleController.swift index 5465b9a6..b1bf5afa 100644 --- a/Example/ChatLayout/Chat/View/Other/BezierBubbleController.swift +++ b/Example/ChatLayout/Chat/View/Other/BezierBubbleController.swift @@ -14,7 +14,6 @@ import Foundation import UIKit final class BezierBubbleController: BubbleController { - private let controllerProxy: BubbleController private let type: MessageType @@ -43,5 +42,4 @@ final class BezierBubbleController: BubbleController { bubbleView.messageType = type bubbleView.bubbleType = bubbleType } - } diff --git a/Example/ChatLayout/Chat/View/Other/BezierMaskedView.swift b/Example/ChatLayout/Chat/View/Other/BezierMaskedView.swift index 0e20829e..829eadc8 100644 --- a/Example/ChatLayout/Chat/View/Other/BezierMaskedView.swift +++ b/Example/ChatLayout/Chat/View/Other/BezierMaskedView.swift @@ -14,7 +14,6 @@ import Foundation import UIKit final class BezierMaskedView: UIView { - lazy var customView = CustomView(frame: bounds) var bubbleType: Cell.BubbleType = .tailed { @@ -33,9 +32,9 @@ final class BezierMaskedView: UIView { var offset: CGFloat { switch bubbleType { case .tailed: - return 2 + 2 case .normal: - return 6 + 6 } } @@ -108,7 +107,6 @@ final class BezierMaskedView: UIView { layer.mask = maskLayer } } - } private func generateIncomingTailedBezierPath(offset: CGFloat, size: CGSize) -> UIBezierPath { diff --git a/Example/ChatLayout/Chat/View/Other/EditNotifier.swift b/Example/ChatLayout/Chat/View/Other/EditNotifier.swift index e47dc834..dde861f0 100644 --- a/Example/ChatLayout/Chat/View/Other/EditNotifier.swift +++ b/Example/ChatLayout/Chat/View/Other/EditNotifier.swift @@ -14,7 +14,6 @@ import Foundation import UIKit final class EditNotifier { - private(set) var isEditing = false private var delegates = NSHashTable.weakObjects() @@ -27,5 +26,4 @@ final class EditNotifier { self.isEditing = isEditing delegates.allObjects.compactMap { $0 as? EditNotifierDelegate }.forEach { $0.setIsEditing(isEditing, duration: duration) } } - } diff --git a/Example/ChatLayout/Chat/View/Other/EditNotifierDelegate.swift b/Example/ChatLayout/Chat/View/Other/EditNotifierDelegate.swift index 90a700be..965a60cc 100644 --- a/Example/ChatLayout/Chat/View/Other/EditNotifierDelegate.swift +++ b/Example/ChatLayout/Chat/View/Other/EditNotifierDelegate.swift @@ -14,20 +14,14 @@ import Foundation import UIKit public enum ActionDuration { - case notAnimated case animated(duration: TimeInterval) - } public protocol EditNotifierDelegate: AnyObject { - func setIsEditing(_ isEditing: Bool, duration: ActionDuration) - } public extension EditNotifierDelegate { - func setIsEditing(_ isEditing: Bool, duration: ActionDuration) {} - } diff --git a/Example/ChatLayout/Chat/View/Other/FullCellContentBubbleController.swift b/Example/ChatLayout/Chat/View/Other/FullCellContentBubbleController.swift index b1b2063e..0baf1cd3 100644 --- a/Example/ChatLayout/Chat/View/Other/FullCellContentBubbleController.swift +++ b/Example/ChatLayout/Chat/View/Other/FullCellContentBubbleController.swift @@ -15,7 +15,6 @@ import Foundation import UIKit final class FullCellContentBubbleController: BubbleController { - weak var bubbleView: BezierMaskedView? { didSet { setupBubbleView() @@ -37,5 +36,4 @@ final class FullCellContentBubbleController: BubbleControlle bubbleView.customView.layoutMargins = .zero } } - } diff --git a/Example/ChatLayout/Chat/View/Other/MainContainerView.swift b/Example/ChatLayout/Chat/View/Other/MainContainerView.swift index 834fd368..12fd1857 100644 --- a/Example/ChatLayout/Chat/View/Other/MainContainerView.swift +++ b/Example/ChatLayout/Chat/View/Other/MainContainerView.swift @@ -15,7 +15,6 @@ import Foundation import UIKit final class MainContainerView: UIView, SwipeNotifierDelegate { - var swipeCompletionRate: CGFloat = 0 { didSet { updateOffsets() @@ -121,5 +120,4 @@ final class MainContainerView CGFloat { switch self { case .linear: - return x + x case .parametric: - return x.parametric + x.parametric case .easeInOut: - return x.quadraticEaseInOut + x.quadraticEaseInOut case .easeIn: - return x.quadraticEaseIn + x.quadraticEaseIn case .easeOut: - return x.quadraticEaseOut + x.quadraticEaseOut } } - } private var displayLink: CADisplayLink? @@ -58,7 +59,8 @@ class ManualAnimator { displayLink = d } - @objc private func tick() { + @objc + private func tick() { let delta = Date().timeIntervalSince(start) var percentage = animationCurve.modify(CGFloat(delta) / CGFloat(total)) if percentage < 0.0 { @@ -74,11 +76,9 @@ class ManualAnimator { displayLink?.invalidate() displayLink = nil } - } private extension CGFloat { - var parametric: CGFloat { guard self > 0.0 else { return 0.0 @@ -121,5 +121,4 @@ private extension CGFloat { } return self * self } - } diff --git a/Example/ChatLayout/Chat/View/Other/SwipeNotifier.swift b/Example/ChatLayout/Chat/View/Other/SwipeNotifier.swift index e00635cf..d6de888e 100644 --- a/Example/ChatLayout/Chat/View/Other/SwipeNotifier.swift +++ b/Example/ChatLayout/Chat/View/Other/SwipeNotifier.swift @@ -14,15 +14,12 @@ import Foundation import UIKit public protocol SwipeNotifierDelegate: AnyObject { - var swipeCompletionRate: CGFloat { get set } var accessorySafeAreaInsets: UIEdgeInsets { get set } - } final class SwipeNotifier { - private var delegates = NSHashTable.weakObjects() private(set) var accessorySafeAreaInsets: UIEdgeInsets = .zero @@ -42,5 +39,4 @@ final class SwipeNotifier { self.accessorySafeAreaInsets = accessorySafeAreaInsets delegates.allObjects.compactMap { $0 as? SwipeNotifierDelegate }.forEach { $0.accessorySafeAreaInsets = accessorySafeAreaInsets } } - } diff --git a/Example/ChatLayout/Chat/View/Other/TextBubbleController.swift b/Example/ChatLayout/Chat/View/Other/TextBubbleController.swift index 9fa684cd..383279bf 100644 --- a/Example/ChatLayout/Chat/View/Other/TextBubbleController.swift +++ b/Example/ChatLayout/Chat/View/Other/TextBubbleController.swift @@ -15,7 +15,6 @@ import Foundation import UIKit final class TextBubbleController: BubbleController { - private let type: MessageType private let bubbleType: Cell.BubbleType @@ -50,5 +49,4 @@ final class TextBubbleController: BubbleController { } } } - } diff --git a/Example/ChatLayout/Chat/View/Other/UIView+Extension.swift b/Example/ChatLayout/Chat/View/Other/UIView+Extension.swift index fc4d8ac2..a6f9897a 100644 --- a/Example/ChatLayout/Chat/View/Other/UIView+Extension.swift +++ b/Example/ChatLayout/Chat/View/Other/UIView+Extension.swift @@ -14,7 +14,6 @@ import Foundation import UIKit extension UIView { - func superview(of type: T.Type) -> T? { superview as? T ?? superview.flatMap { $0.superview(of: type) } } @@ -37,7 +36,6 @@ extension UIView { isHidden = newValue } } - } extension UIViewController { diff --git a/Example/ChatLayout/Chat/View/ReloadDelegate.swift b/Example/ChatLayout/Chat/View/ReloadDelegate.swift index 85fba09f..1af01237 100644 --- a/Example/ChatLayout/Chat/View/ReloadDelegate.swift +++ b/Example/ChatLayout/Chat/View/ReloadDelegate.swift @@ -13,7 +13,5 @@ import Foundation protocol ReloadDelegate: AnyObject { - func reloadMessage(with id: UUID) - } diff --git a/Example/ChatLayout/Chat/View/Status View/StatusView.swift b/Example/ChatLayout/Chat/View/Status View/StatusView.swift index e53d7824..27520818 100644 --- a/Example/ChatLayout/Chat/View/Status View/StatusView.swift +++ b/Example/ChatLayout/Chat/View/Status View/StatusView.swift @@ -15,7 +15,6 @@ import Foundation import UIKit final class StatusView: UIView, StaticViewFactory { - private lazy var imageView = UIImageView(frame: bounds) override init(frame: CGRect) { @@ -64,5 +63,4 @@ final class StatusView: UIView, StaticViewFactory { imageView.tintColor = .systemBlue } } - } diff --git a/Example/ChatLayout/Chat/View/Text Message View/TextMessageController.swift b/Example/ChatLayout/Chat/View/Text Message View/TextMessageController.swift index 7e12d326..31e77ea6 100644 --- a/Example/ChatLayout/Chat/View/Text Message View/TextMessageController.swift +++ b/Example/ChatLayout/Chat/View/Text Message View/TextMessageController.swift @@ -13,7 +13,6 @@ import Foundation final class TextMessageController { - weak var view: TextMessageView? { didSet { view?.reloadData() @@ -31,5 +30,4 @@ final class TextMessageController { self.type = type self.bubbleController = bubbleController } - } diff --git a/Example/ChatLayout/Chat/View/Text Message View/TextMessageView.swift b/Example/ChatLayout/Chat/View/Text Message View/TextMessageView.swift index c9a704f3..4829637c 100644 --- a/Example/ChatLayout/Chat/View/Text Message View/TextMessageView.swift +++ b/Example/ChatLayout/Chat/View/Text Message View/TextMessageView.swift @@ -15,7 +15,6 @@ import Foundation import UIKit final class TextMessageView: UIView, ContainerCollectionViewCellDelegate { - private var viewPortWidth: CGFloat = 300 private lazy var textView = MessageTextView() @@ -127,7 +126,6 @@ final class TextMessageView: UIView, ContainerCollectionViewCellDelegate { setNeedsLayout() } } - } extension TextMessageView: AvatarViewDelegate { @@ -144,7 +142,6 @@ extension TextMessageView: AvatarViewDelegate { /// UITextView with hacks to avoid selection private final class MessageTextView: UITextView { - override var isFocused: Bool { false } @@ -160,5 +157,4 @@ private final class MessageTextView: UITextView { override func canPerformAction(_ action: Selector, withSender sender: Any?) -> Bool { false } - } diff --git a/Example/ChatLayout/Chat/View/URL View/URLController.swift b/Example/ChatLayout/Chat/View/URL View/URLController.swift index 7d468b5d..50312cd5 100644 --- a/Example/ChatLayout/Chat/View/URL View/URLController.swift +++ b/Example/ChatLayout/Chat/View/URL View/URLController.swift @@ -15,7 +15,6 @@ import LinkPresentation @available(iOS 13, *) final class URLController { - let url: URL var metadata: LPLinkMetadata? @@ -71,7 +70,5 @@ final class URLController { } } } - } - } diff --git a/Example/ChatLayout/Chat/View/URL View/URLSource.swift b/Example/ChatLayout/Chat/View/URL View/URLSource.swift index 5ec1dbd7..fcd580f8 100644 --- a/Example/ChatLayout/Chat/View/URL View/URLSource.swift +++ b/Example/ChatLayout/Chat/View/URL View/URLSource.swift @@ -13,21 +13,18 @@ import Foundation struct URLSource: Hashable { - let url: URL var isPresentLocally: Bool { if #available(iOS 13, *) { - return metadataCache.isEntityCached(for: url) + metadataCache.isEntityCached(for: url) } else { - return true + true } - } func hash(into hasher: inout Hasher) { hasher.combine(url) hasher.combine(isPresentLocally) } - } diff --git a/Example/ChatLayout/Chat/View/URL View/URLView.swift b/Example/ChatLayout/Chat/View/URL View/URLView.swift index 22509847..4f5f0de8 100644 --- a/Example/ChatLayout/Chat/View/URL View/URLView.swift +++ b/Example/ChatLayout/Chat/View/URL View/URLView.swift @@ -17,7 +17,6 @@ import UIKit @available(iOS 13, *) final class URLView: UIView, ContainerCollectionViewCellDelegate { - private var linkView: LPLinkView? private var controller: URLController? @@ -124,5 +123,4 @@ final class URLView: UIView, ContainerCollectionViewCellDelegate { setNeedsLayout() layoutIfNeeded() } - } diff --git a/Example/ChatLayout/ProcessInfo+Extension.swift b/Example/ChatLayout/ProcessInfo+Extension.swift index e89505aa..fbcad794 100644 --- a/Example/ChatLayout/ProcessInfo+Extension.swift +++ b/Example/ChatLayout/ProcessInfo+Extension.swift @@ -13,9 +13,7 @@ import Foundation extension ProcessInfo { - static var isRunningTests: Bool { processInfo.environment["XCTestConfigurationFilePath"] != nil } - } diff --git a/Example/ChatLayout/SceneDelegate.swift b/Example/ChatLayout/SceneDelegate.swift index 9c7b109e..0cb76b83 100644 --- a/Example/ChatLayout/SceneDelegate.swift +++ b/Example/ChatLayout/SceneDelegate.swift @@ -13,7 +13,6 @@ import UIKit class SceneDelegate: UIResponder, UIWindowSceneDelegate { - var window: UIWindow? @available(iOS 13.0, *) diff --git a/Example/Tests/HelpersTests.swift b/Example/Tests/HelpersTests.swift index f7d8828a..bd7e8bbc 100644 --- a/Example/Tests/HelpersTests.swift +++ b/Example/Tests/HelpersTests.swift @@ -15,7 +15,6 @@ import Foundation import XCTest final class HelpersTests: XCTestCase { - func testItemKindInit() { let header = ItemKind(UICollectionView.elementKindSectionHeader) XCTAssertTrue(header == ItemKind.header) @@ -46,11 +45,11 @@ final class HelpersTests: XCTestCase { func testBinarySearch() { let predicate: (Int) -> ComparisonResult = { integer in if integer < 100 { - return .orderedAscending + .orderedAscending } else if integer > 100 { - return .orderedDescending + .orderedDescending } else { - return .orderedSame + .orderedSame } } XCTAssertEqual([Int]().binarySearch(predicate: predicate), nil) @@ -96,11 +95,11 @@ final class HelpersTests: XCTestCase { func testSearchInRange() { let predicate: (Int) -> ComparisonResult = { integer in if integer < 100 { - return .orderedAscending + .orderedAscending } else if integer > 200 { - return .orderedDescending + .orderedDescending } else { - return .orderedSame + .orderedSame } } XCTAssertEqual([Int]().binarySearchRange(predicate: predicate), []) @@ -132,5 +131,4 @@ final class HelpersTests: XCTestCase { XCTAssertEqual(dictionary[.exact(.zero)], 3) XCTAssertEqual(dictionary[.exact(size)], 4) } - } diff --git a/Example/Tests/MockCollectionLayout.swift b/Example/Tests/MockCollectionLayout.swift index 7f571cb0..fc014e84 100644 --- a/Example/Tests/MockCollectionLayout.swift +++ b/Example/Tests/MockCollectionLayout.swift @@ -15,7 +15,6 @@ import Foundation import UIKit class MockCollectionLayout: ChatLayoutRepresentation, ChatLayoutDelegate { - var numberOfItemsInSection: [Int: Int] = [0: 100, 1: 100, 2: 100] var shouldPresentHeaderAtSection: [Int: Bool] = [0: true, 1: true, 2: true] var shouldPresentFooterAtSection: [Int: Bool] = [0: true, 1: true, 2: true] @@ -98,5 +97,4 @@ class MockCollectionLayout: ChatLayoutRepresentation, ChatLayoutDelegate { } return sections } - } diff --git a/Example/Tests/MockUICollectionViewUpdateItem.swift b/Example/Tests/MockUICollectionViewUpdateItem.swift index 7f792771..9d6863f8 100644 --- a/Example/Tests/MockUICollectionViewUpdateItem.swift +++ b/Example/Tests/MockUICollectionViewUpdateItem.swift @@ -15,7 +15,6 @@ import Foundation import UIKit class MockUICollectionViewUpdateItem: UICollectionViewUpdateItem { - // swiftlint:disable identifier_name var _indexPathBeforeUpdate: IndexPath? var _indexPathAfterUpdate: IndexPath? @@ -40,5 +39,4 @@ class MockUICollectionViewUpdateItem: UICollectionViewUpdateItem { override var updateAction: Action { _updateAction } - } diff --git a/Example/Tests/PerformanceTests.swift b/Example/Tests/PerformanceTests.swift index 9573d1d3..5ffd0f50 100644 --- a/Example/Tests/PerformanceTests.swift +++ b/Example/Tests/PerformanceTests.swift @@ -15,16 +15,15 @@ import Foundation import XCTest final class PerformanceTests: XCTestCase { - func testBinarySearchPerformance() { let constant = 1257 let predicate: (Int) -> ComparisonResult = { integer in if integer < constant { - return .orderedAscending + .orderedAscending } else if integer > constant { - return .orderedDescending + .orderedDescending } else { - return .orderedSame + .orderedSame } } let values = (0...100000).map { $0 } @@ -40,11 +39,11 @@ final class PerformanceTests: XCTestCase { let constant = 1257 let predicate: (Int) -> ComparisonResult = { integer in if integer < constant { - return .orderedAscending + .orderedAscending } else if integer > constant + 111 { - return .orderedDescending + .orderedDescending } else { - return .orderedSame + .orderedSame } } let values = (0...100000).map { $0 } @@ -76,7 +75,6 @@ final class PerformanceTests: XCTestCase { _ = layout.controller.layoutAttributesForElements(in: rect, state: .beforeUpdate, ignoreCache: true) } } - } func testInsertionPerformance() { @@ -131,5 +129,4 @@ final class PerformanceTests: XCTestCase { } } } - } diff --git a/Example/Tests/StateControllerInternalTests.swift b/Example/Tests/StateControllerInternalTests.swift index ac2ed4a6..1f1e5dfd 100644 --- a/Example/Tests/StateControllerInternalTests.swift +++ b/Example/Tests/StateControllerInternalTests.swift @@ -14,7 +14,6 @@ import XCTest class StateControllerInternalTests: XCTestCase { - func testUpdatePreferredSize() { let layout = MockCollectionLayout() layout.controller.set(layout.getPreparedSections(), at: .beforeUpdate) @@ -139,5 +138,4 @@ class StateControllerInternalTests: XCTestCase { XCTAssertEqual(layout.controller.contentHeight(at: .beforeUpdate), estimatedContentHeight) XCTAssertEqual(layout.controller.contentSize(for: .beforeUpdate), CGSize(width: layout.viewSize.width - 0.0001, height: estimatedContentHeight)) } - } diff --git a/Example/Tests/StateControllerProcessUpdatesTests.swift b/Example/Tests/StateControllerProcessUpdatesTests.swift index d50498e2..aece4a70 100644 --- a/Example/Tests/StateControllerProcessUpdatesTests.swift +++ b/Example/Tests/StateControllerProcessUpdatesTests.swift @@ -14,7 +14,6 @@ import XCTest class StateControllerProcessUpdatesTests: XCTestCase { - override func setUp() { super.setUp() // Put setup code here. This method is called before the invocation of each test method in the class. @@ -375,5 +374,4 @@ class StateControllerProcessUpdatesTests: XCTestCase { XCTAssertEqual(layout.controller.numberOfItems(in: 0, at: .beforeUpdate), 3) XCTAssertEqual(layout.controller.numberOfItems(in: 0, at: .afterUpdate), 4) } - }