FetchedResultsControllerCollectionViewUpdater
描述
处理 UICollectionView 中 beginUpdates()
和 endUpdates()
方法缺失的简单方法。提供 NSFetchedResultsControllerDelegate 的实现,用于更新 UICollectionView 的内容。
使用示例
@IBOutlet weak var collectionView: UICollectionView!
lazy var collectionUpdaterDelegate: CollectionViewUpdaterDelegate = {
let delegate = CollectionViewUpdaterDelegate(collectionView: collectionView)
// Optionally add section name modifier
delegate.sectionIndexTitleForSectionName = { sectionName in
sectionName.uppercased()
}
return delegate
}()
lazy var fetchedResultsController: NSFetchedResultsController<NSManagedObject> = {
let frc: NSFetchedResultsController<NSManagedObject>
// FRC init and setup
frc.delegate = collectionUpdaterDelegate
return frc
}()
override func viewDidLoad() {
do {
try fetchedResultsController.performFetch()
} catch {
handleError(error)
}
}
安装
FetchedResultsControllerCollectionViewUpdater 通过 CocoaPods 提供。要安装它,只需将以下行添加到您的 Podfile 中
pod 'FetchedResultsControllerCollectionViewUpdater'
作者
Artem Garmash,agarmash.com
许可协议
FetchedResultsControllerCollectionViewUpdater遵守MIT许可协议。有关更多信息,请参阅LICENSE文件。