|
| 1 | +// |
| 2 | +// UICollectionView+ApplyStyle.swift |
| 3 | +// ApplyStyleKit |
| 4 | +// |
| 5 | +// Created by shindyu on 2018/12/22. |
| 6 | +// Copyright © 2018 shindyu. All rights reserved. |
| 7 | +// |
| 8 | + |
| 9 | +extension StyleObject where Base: UICollectionView { |
| 10 | + @discardableResult public func collectionViewLayout(_ layout: UICollectionViewLayout) -> StyleObject { |
| 11 | + base.collectionViewLayout = layout |
| 12 | + return self |
| 13 | + } |
| 14 | + |
| 15 | + @discardableResult public func delegate(_ delegate: UICollectionViewDelegate?) -> StyleObject { |
| 16 | + base.delegate = delegate |
| 17 | + return self |
| 18 | + } |
| 19 | + |
| 20 | + @discardableResult public func dataSource(_ dataSource: UICollectionViewDataSource?) -> StyleObject { |
| 21 | + base.dataSource = dataSource |
| 22 | + return self |
| 23 | + } |
| 24 | + |
| 25 | + @available(iOS 10.0, *) |
| 26 | + @discardableResult public func prefetchDataSource(_ dataSource: UICollectionViewDataSourcePrefetching?) -> StyleObject { |
| 27 | + base.prefetchDataSource = dataSource |
| 28 | + return self |
| 29 | + } |
| 30 | + |
| 31 | + @available(iOS 10.0, *) |
| 32 | + @discardableResult public func isPrefetchingEnabled(_ enabled: Bool) -> StyleObject { |
| 33 | + base.isPrefetchingEnabled = enabled |
| 34 | + return self |
| 35 | + } |
| 36 | + |
| 37 | + @available(iOS 11.0, *) |
| 38 | + @discardableResult public func dragDelegate(_ delegate: UICollectionViewDragDelegate?) -> StyleObject { |
| 39 | + base.dragDelegate = delegate |
| 40 | + return self |
| 41 | + } |
| 42 | + |
| 43 | + @available(iOS 11.0, *) |
| 44 | + @discardableResult public func dropDelegate(_ delegate: UICollectionViewDropDelegate?) -> StyleObject { |
| 45 | + base.dropDelegate = delegate |
| 46 | + return self |
| 47 | + } |
| 48 | + |
| 49 | + @available(iOS 11.0, *) |
| 50 | + @discardableResult public func dragInteractionEnabled(_ enabled: Bool) -> StyleObject { |
| 51 | + base.dragInteractionEnabled = enabled |
| 52 | + return self |
| 53 | + } |
| 54 | + |
| 55 | + @available(iOS 11.0, *) |
| 56 | + @discardableResult public func reorderingCadence(_ cadence: UICollectionView.ReorderingCadence) -> StyleObject { |
| 57 | + base.reorderingCadence = cadence |
| 58 | + return self |
| 59 | + } |
| 60 | + |
| 61 | + @discardableResult public func backgroundView(_ view: UIView) -> StyleObject { |
| 62 | + base.backgroundView = view |
| 63 | + return self |
| 64 | + } |
| 65 | + |
| 66 | + @discardableResult public func register(_ cellClass: AnyClass?, forCellWithReuseIdentifier identifier: String) -> StyleObject { |
| 67 | + base.register(cellClass, forCellWithReuseIdentifier: identifier) |
| 68 | + return self |
| 69 | + } |
| 70 | + |
| 71 | + @discardableResult public func register(_ nib: UINib?, forCellWithReuseIdentifier identifier: String) -> StyleObject { |
| 72 | + base.register(nib, forCellWithReuseIdentifier: identifier) |
| 73 | + return self |
| 74 | + } |
| 75 | + |
| 76 | + @discardableResult public func register(_ viewClass: AnyClass?, forSupplementaryViewOfKind elementKind: String, withReuseIdentifier identifier: String) -> StyleObject { |
| 77 | + base.register(viewClass, forSupplementaryViewOfKind: elementKind, withReuseIdentifier: identifier) |
| 78 | + return self |
| 79 | + } |
| 80 | + |
| 81 | + @discardableResult public func register(_ nib: UINib?, forSupplementaryViewOfKind kind: String, withReuseIdentifier identifier: String) -> StyleObject { |
| 82 | + base.register(nib, forSupplementaryViewOfKind: kind, withReuseIdentifier: identifier) |
| 83 | + return self |
| 84 | + } |
| 85 | + |
| 86 | + @discardableResult public func allowsSelection(_ enabled: Bool) -> StyleObject { |
| 87 | + base.allowsSelection = enabled |
| 88 | + return self |
| 89 | + } |
| 90 | + |
| 91 | + @discardableResult public func allowsMultipleSelection(_ enabled: Bool) -> StyleObject { |
| 92 | + base.allowsMultipleSelection = enabled |
| 93 | + return self |
| 94 | + } |
| 95 | + |
| 96 | + @discardableResult public func selectItem(at indexPath: IndexPath?, animated: Bool, scrollPosition: UICollectionView.ScrollPosition) -> StyleObject { |
| 97 | + base.selectItem(at: indexPath, animated: animated, scrollPosition: scrollPosition) |
| 98 | + return self |
| 99 | + } |
| 100 | + |
| 101 | + @discardableResult public func deselectItem(at indexPath: IndexPath, animated: Bool) -> StyleObject { |
| 102 | + base.deselectItem(at: indexPath, animated: animated) |
| 103 | + return self |
| 104 | + } |
| 105 | + |
| 106 | + @discardableResult public func reloadData() -> StyleObject { |
| 107 | + base.reloadData() |
| 108 | + return self |
| 109 | + } |
| 110 | + |
| 111 | + @discardableResult public func setCollectionViewLayout(_ layout: UICollectionViewLayout, animated: Bool) -> StyleObject { |
| 112 | + base.setCollectionViewLayout(layout, animated: animated) |
| 113 | + return self |
| 114 | + } |
| 115 | + |
| 116 | + @discardableResult public func setCollectionViewLayout(_ layout: UICollectionViewLayout, animated: Bool, completion: ((Bool) -> Void)? = nil) -> StyleObject { |
| 117 | + base.setCollectionViewLayout(layout, animated: animated, completion: completion) |
| 118 | + return self |
| 119 | + } |
| 120 | + |
| 121 | + @discardableResult public func finishInteractiveTransition() -> StyleObject { |
| 122 | + base.finishInteractiveTransition() |
| 123 | + return self |
| 124 | + } |
| 125 | + |
| 126 | + @discardableResult public func cancelInteractiveTransition() -> StyleObject { |
| 127 | + base.cancelInteractiveTransition() |
| 128 | + return self |
| 129 | + } |
| 130 | + |
| 131 | + @discardableResult public func scrollToItem(at indexPath: IndexPath, at scrollPosition: UICollectionView.ScrollPosition, animated: Bool) -> StyleObject { |
| 132 | + base.scrollToItem(at: indexPath, at: scrollPosition, animated: animated) |
| 133 | + return self |
| 134 | + } |
| 135 | + |
| 136 | + @discardableResult public func insertSections(_ sections: IndexSet) -> StyleObject { |
| 137 | + base.insertSections(sections) |
| 138 | + return self |
| 139 | + } |
| 140 | + |
| 141 | + @discardableResult public func deleteSections(_ sections: IndexSet) -> StyleObject { |
| 142 | + base.deleteSections(sections) |
| 143 | + return self |
| 144 | + } |
| 145 | + |
| 146 | + @discardableResult public func reloadSections(_ sections: IndexSet) -> StyleObject { |
| 147 | + base.reloadSections(sections) |
| 148 | + return self |
| 149 | + } |
| 150 | + |
| 151 | + @discardableResult public func moveSection(_ section: Int, toSection newSection: Int) -> StyleObject { |
| 152 | + base.moveSection(section, toSection: newSection) |
| 153 | + return self |
| 154 | + } |
| 155 | + |
| 156 | + @discardableResult public func insertItems(at indexPaths: [IndexPath]) -> StyleObject { |
| 157 | + base.insertItems(at: indexPaths) |
| 158 | + return self |
| 159 | + } |
| 160 | + |
| 161 | + @discardableResult public func deleteItems(at indexPaths: [IndexPath]) -> StyleObject { |
| 162 | + base.deleteItems(at: indexPaths) |
| 163 | + return self |
| 164 | + } |
| 165 | + |
| 166 | + @discardableResult public func reloadItems(at indexPaths: [IndexPath]) -> StyleObject { |
| 167 | + base.reloadItems(at: indexPaths) |
| 168 | + return self |
| 169 | + } |
| 170 | + |
| 171 | + @discardableResult public func moveItem(at indexPath: IndexPath, to newIndexPath: IndexPath) -> StyleObject { |
| 172 | + base.moveItem(at: indexPath, to: newIndexPath) |
| 173 | + return self |
| 174 | + } |
| 175 | + |
| 176 | + @discardableResult public func performBatchUpdates(_ updates: (() -> Void)?, completion: ((Bool) -> Void)? = nil) -> StyleObject { |
| 177 | + base.performBatchUpdates(updates, completion: completion) |
| 178 | + return self |
| 179 | + } |
| 180 | + |
| 181 | + @discardableResult public func updateInteractiveMovementTargetPosition(_ targetPosition: CGPoint) -> StyleObject { |
| 182 | + base.updateInteractiveMovementTargetPosition(targetPosition) |
| 183 | + return self |
| 184 | + } |
| 185 | + |
| 186 | + @discardableResult public func endInteractiveMovement() -> StyleObject { |
| 187 | + base.endInteractiveMovement() |
| 188 | + return self |
| 189 | + } |
| 190 | + |
| 191 | + @discardableResult public func cancelInteractiveMovement() -> StyleObject { |
| 192 | + base.cancelInteractiveMovement() |
| 193 | + return self |
| 194 | + } |
| 195 | + |
| 196 | + @discardableResult public func remembersLastFocusedIndexPath(_ enabled: Bool) -> StyleObject { |
| 197 | + base.remembersLastFocusedIndexPath = enabled |
| 198 | + return self |
| 199 | + } |
| 200 | +} |
0 commit comments