有人可以帮我修复这个警告吗?
冗余一致性约束"T":"可重用视图">
我到处搜索,没有发现任何有用的东西。
import UIKit
extension UICollectionView {
func register<T: UICollectionViewCell>(_: T.Type) where T: ReusableView, T: NibLoadableView {
//warning: Redundant conformance constraint 'T': 'ReusableView'
let nib = UINib(nibName: T.nibName, bundle: nil)
register(nib, forCellWithReuseIdentifier: T.reuseIdentifier)
}
func dequeueReusableCell<T: UICollectionViewCell>(forIndexPath indexPath: IndexPath) -> T where T: ReusableView {
//warning: Redundant conformance constraint 'T': 'ReusableView'
guard let cell = dequeueReusableCell(withReuseIdentifier: T.reuseIdentifier, for: indexPath as IndexPath) as? T else {
fatalError("Could not dequeue cell with identifier: (T.reuseIdentifier)")
}
return cell
}
}
extension UICollectionViewCell: ReusableView {}
首先,编译器警告约束是多余的。这不是错误。您可以保持原样。
如何修复警告?
您的UICollectionViewCell已经在代码中的某个位置进行了扩展,以符合ReusableView
协议。
这就是为什么您不必再次应用此约束的原因。
func register<T: UICollectionViewCell>(_: T.Type) where T: NibLoadableView {
}
它是否会影响我应用程序的行为?
这对应用程序的行为没有影响,因为删除的约束是redundant
的,如警告中所述。