Files
raspberry/iOS/Wallet/Sources/Common/Extension/CommonUICollectionView.swift
2022-12-13 22:46:16 +03:00

29 lines
1.0 KiB
Swift

//
// UICollectionView.swift
// Wallet
//
// Created by Igor on 05.03.2021.
// Copyright © 2021 AM. All rights reserved.
//
import UIKit
extension UICollectionViewCell {
fileprivate static var _cellId: String { String(describing: self) }
fileprivate static var _xibName: String { String(describing: self).components(separatedBy: ".").last! }
}
extension UICollectionView {
func register<T: UICollectionViewCell>(cell: T.Type, identifier: String? = nil) {
if Bundle.main.path(forResource: cell._xibName, ofType: "nib") != nil {
register(UINib(nibName: cell._xibName, bundle: nil), forCellWithReuseIdentifier: identifier ?? cell._cellId)
} else {
register(cell, forCellWithReuseIdentifier: identifier ?? cell._cellId)
}
}
func dequeueReusableCell<T: UICollectionViewCell>(_ type: T.Type, indexPath: IndexPath, identifier: String? = nil) -> T {
// swiftlint:disable force_cast
dequeueReusableCell(withReuseIdentifier: identifier ?? T._cellId, for: indexPath) as! T
}
}